Open joshspicer opened 5 years ago
In general, we need to do a bit better with errors. We should have a structure similar to the .Net generator, where all errors have a code and message property, and the message becomes the exception message, when present. We should also have a way of representing custom error information, either as a property of our exception, or by creating a separate exception type.
We are looking to support custom errors as supplied by the swagger file. Right now AutoREST is simply expecting a
code
andmessage
at the top level of any error response, else it will ignore any other response and throw a generic error.I'm setting the swagger
default
field, and would like to define a response shape that autorest can then parse and convert into a powershell error.For example, here is the structure of an ODATA error response. I'm setting this as the default response schema in my swagger.
At its current state, AutoREST will not be able to parse this error properly and will ignore it entirely.
Our idea to implement proper error handling is to allow specifying the location of the error code and error message in the Swagger itself (perhaps with the format option, as shown below).
AutoREST can then parse whatever is specified as the "default" response, and can pick out the correct error data to present to the user.
We found that the code emitting methods
onDefault
in fileextensions\powershell\cmdlet-class.ts
(around line 500) can be adapted to behave this way.cc: @kenal-microsoft @amareshbAtMicrosoft