def restrict_len(content):
    if len(content) > 320:
        content = content[:310].strip() + '...'
    return content


def detect_language(config, langs, word):
    from yandex_translate import YandexTranslate
    translator = YandexTranslate(config['yandex_translate_key'])
    russian = 'абвгдеёжзийклмнопрстуфхцчшщъыьэюя'

    if word[0] in russian:
        lang = 'ru'
    else:
        lang = translator.detect(word)
        if lang not in langs:
            lang = 'en'
    return lang

def restrict_len(content):
    if len(content) > 320:
        content = content[:310].strip() + '...'
    return content


def detect_language(config, langs, word):
    from yandex_translate import YandexTranslate, YandexTranslateException
    translator = YandexTranslate(config['yandex_translate_key'])
    russian = 'абвгдеёжзийклмнопрстуфхцчшщъыьэюя'

    if word[0] in russian:
        lang = 'ru'
    else:
        try:
            lang = translator.detect(word)
        except YandexTranslateException:
            lang = 'en'
        if lang not in langs:
            lang = 'en'
    return lang

Add unknown language error catching
Add unknown language error catching

  def restrict_len(content):
      if len(content) > 320:
          content = content[:310].strip() + '...'
      return content
  
  
  def detect_language(config, langs, word):
-     from yandex_translate import YandexTranslate
+     from yandex_translate import YandexTranslate, YandexTranslateException
      translator = YandexTranslate(config['yandex_translate_key'])
      russian = 'абвгдеёжзийклмнопрстуфхцчшщъыьэюя'
  
      if word[0] in russian:
          lang = 'ru'
      else:
+         try:
-         lang = translator.detect(word)
+             lang = translator.detect(word)
+         except YandexTranslateException:
+             lang = 'en'
          if lang not in langs:
              lang = 'en'
      return lang
  
Add unknown language error catching
## Code Before:
def restrict_len(content):
    if len(content) > 320:
        content = content[:310].strip() + '...'
    return content


def detect_language(config, langs, word):
    from yandex_translate import YandexTranslate
    translator = YandexTranslate(config['yandex_translate_key'])
    russian = 'абвгдеёжзийклмнопрстуфхцчшщъыьэюя'

    if word[0] in russian:
        lang = 'ru'
    else:
        lang = translator.detect(word)
        if lang not in langs:
            lang = 'en'
    return lang

## Instruction:
Add unknown language error catching
## Code After:
def restrict_len(content):
    if len(content) > 320:
        content = content[:310].strip() + '...'
    return content


def detect_language(config, langs, word):
    from yandex_translate import YandexTranslate, YandexTranslateException
    translator = YandexTranslate(config['yandex_translate_key'])
    russian = 'абвгдеёжзийклмнопрстуфхцчшщъыьэюя'

    if word[0] in russian:
        lang = 'ru'
    else:
        try:
            lang = translator.detect(word)
        except YandexTranslateException:
            lang = 'en'
        if lang not in langs:
            lang = 'en'
    return lang
