Azure-sdk-for-js: RestError thrown with JSON in message

Created on 24 Apr 2020  路  5Comments  路  Source: Azure/azure-sdk-for-js

  • Package Name: @azure/cognitiveservices-translatortext
  • Package Version: 1.0.0
  • Operating system: Windows 10 2004 OS Build 19041.207
  • [ ] nodejs

    • version:

  • [x] browser

    • name/version: Edge Chromium Dev: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.3 Safari/537.36 Edg/83.0.478.5

  • [x] typescript

    • version: 3.8.3

  • Is the bug related to documentation in

Describe the bug
In the case below, the RestError thrown isn't conveniently typed. The code property is undefined, and the message property is JSON with a code and message.

To Reproduce
Steps to reproduce the behavior:

  1. git clone https://github.com/nguerrera/translator
  2. cd translator
  3. git checkout repro-error-issue
  4. npm install
  5. npm start
  6. Navigate to http://localhost:8080 in a browser
  7. Open debug console (F12)
  8. Enter 12345678901234567890123456789012 as API key to trigger auth error (It has to be 32 chars as the code doesn't bother trying to connect otherwise)
  9. Click translate button
  10. Examine console log while referencing code here: https://github.com/nguerrera/translator/blob/ae45c9158a48e197d146703eb4aee0313b6b1208/src/index.ts#L124-L128

Expected behavior
error.message is The request is not authorized because credentials are missing or invalid.
error.code is 401000

Actual behavior
error.code is undefined
error.message is {"error":{"code":401000,"message":"The request is not authorized because credentials are missing or invalid."}}

Screenshots
image

Additional context
N/A

Client Cognitive - Translator question

All 5 comments

(You can remove the "customer-reported" tag. I work at Microsoft, just joined the team, and found this while experimenting as a ramping up exercise.)

@sarangan12, This seems to be similar to the issue we had with storage when parsing the error response. Can you take a look?

Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc @dfulcer.

@ramya-rao-a Yes. I have confirmed. This is same as the storage issue https://github.com/Azure/azure-sdk-for-js/issues/4999. The Code changes have been completed in core-http package in PR https://github.com/Azure/azure-sdk-for-js/pull/5437.

This issue deals with translator text which depends on the ms-rest-js. So, the issue is still happening. Do you want the same fix to be ported to ms-rest-js? Please let me know.

Yes, lets port the fix over to ms-rest-js

Was this page helpful?
0 / 5 - 0 ratings