Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bad request 400 on dictionary lookup. #12

Open
Juffff opened this issue Nov 17, 2023 · 0 comments
Open

Bad request 400 on dictionary lookup. #12

Juffff opened this issue Nov 17, 2023 · 0 comments

Comments

@Juffff
Copy link

Juffff commented Nov 17, 2023

I'm using dictionary lookup for finding alternative translations.

dictionaryLookupMS = async (data) => {
const key = "myKey";
const endpoint = https://api.cognitive.microsofttranslator.com/dictionary/lookup?api-version=3.0&from=${data.originLanguageCode}&to=${data.translationLanguageCode};
const location = "westeurope";
const text = data.text;

try {
  const response = await axios({
    baseURL: endpoint,
    method: "post",
    headers: {
      "Ocp-Apim-Subscription-Key": key,
      "Ocp-Apim-Subscription-Region": location,
      "Content-type": "application/json",
      "X-ClientTraceId": uuidv4().toString(),
    },
  ,
    data: [{
      "text": text,
    }],
    responseType: "json",
  });
  return response.data;
} catch (error) {
  logger.onError(error, operationTypes.dictionaryLookupMS, `${data.originLanguageCode} -> ${data.translationLanguageCode}: ${data.text}`);
  return [];
}

};

When origin language code is for example us and target is uk everything works fine. I get that I want. But when the origin language code is es and and target is ru I get an error:

AxiosError: Request failed with status code 400
...
code: 'ERR_BAD_REQUEST',

config: {
transitional: {
silentJSONParsing: true,
forcedJSONParsing: true,
clarifyTimeoutError: false
}
...

It means that the code works fine, but something wrong with es code at endpoint. In docs there are information that requested languages support dictionary lookup. May be anyone can try this language pair and check if it work? Any suggestions?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant