azure-sdk-for-python: Exception messages in Python not showing nicely

I generated a client with Autorest for C#, Node.js, and for Python as well. When my API is returning an error, I send back an503 status code with some error details in a JSON.

When I use my Node.js library and meet an error, I have a nice error message on the output of my script. See the second line

C:\Program Files\nodejs\node.exe .\index.js
(node:29056) UnhandledPromiseRejectionWarning: Error: {"code":400,"error":{"global":["MY-ERROR-MESSAGE-THAT-IS-COMING-FROM-THE-API"]}}
    at new RestError (c:\Users\Jorgos\Downloads\MyTests\node_modules\@azure\ms-rest-js\dist\msRest.node.js:2480:28)
    at c:\Users\Jorgos\Downloads\MyTests\node_modules\@azure\ms-rest-js\dist\msRest.node.js:3687:37
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
    at async c:\Users\Jorgos\Downloads\MyTests\index.js:16:13
(Use `node --trace-warnings ...` to show where the warning was created)
(node:29056) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 2)
(node:29056) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

When I use the Python client, the error message is not so nice

  File "C:/Users/Jorgos/Dev/Workspace/my-test/python/main.py", line 16, in <module>
    client.my_method(body=MyMethodRequest(my_parameter="myValue"))
  File "c:\users\jorgos\appdata\roaming\python\python38\site-packages\my-company\my-package\my_client.py", line 1137, in my_method
    raise models.ProblemResponseException(self._deserialize, response)
my-company.my-client.models.problem_response_py3.ProblemResponseException: Operation returned an invalid status code 'Bad Request'

Process finished with exit code 1

The issue is that the users of the library don’t know what is their issue when they use Python. There is only a status code, but there is no error message printed, such as in the case with the Node.js package

I try to prevent putting the example scripts in a try-catch block and printing the error message in the catch block. Because I would like to keep the example scripts as clean as possible.

Do you have any suggestions on what to do here? Or do I miss something?

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 2
  • Comments: 27 (14 by maintainers)

Most upvoted comments

@brnbs @techwithtim I’m starting work on a PR now!

Yes, I can confirm that it works now. I think you can close the issue.

Thanks for your patience as well.

hey @deaktomi we have a PR open for it now, will give more updates on release later. Thanks so much for your patience!

+1 we need this feature ASAP

@deaktomi thanks for raising this issue! this is something we’ve been thinking about on the python azure-core side, to include more of the raw body in the output. Let me transfer this issue to the azure-sdk-for-python repo, and add it to our current milestone