Azure / Azure/autorest.powershell

Supporting custom default errors

Open
#460 1 comment 0 reactions 0 assignees View on GitHub
question
Dominant language
C#
Stars
123
Forks
99
PR merge metrics
No merged PRs in 30d

Description

We are looking to support custom errors as supplied by the swagger file. Right now AutoREST is simply expecting a `code` and `message` 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.

```json
{
"odata.error": {
"code": "string",
"message": {
"lang": "string",
"value": "string"
},
"innererror": {
"message": "string",
"type": "string",
"stacktrace": "string"
}
}
}
```

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).

```yaml
definitions:
default_error:
type: object
properties:
odata.error:
properties:
code:
type: string
format: ERROR_CODE
message:
type: object
properties:
lang:
type: string
value:
type: string
innererror:
type: object
properties:
message:
type: string
format: ERROR_MESSAGE
type:
type: string
stacktrace:
type: string
```

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 file `extensions\powershell\cmdlet-class.ts` (around line 500) can be adapted to behave this way.

cc: @kenal-microsoft @amareshbAtMicrosoft

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.