Azure schema registry SDK does not have a "schema does not exist" return value
See original GitHub issueIs your feature request related to a problem? Please describe.
When retrieving a schema with a method like SchemaRegistryClient.getSchemaId
or SchemaRegistryClient.getSchemaById
, an error is thrown if the schema does not exists.
This does not leave me with a clear way to differentiate a functional error (the schema doesn’t exists) from a technical errors (like ‘there is no network connection’ or’ you are not authorized to retrieve schemas’)
Describe the solution you’d like
The current signature of these 2 methods is:
getSchemaId(schema: SchemaDescription, options?: GetSchemaIdOptions): Promise<SchemaId>;
getSchemaById(id: string, options?: GetSchemaByIdOptions): Promise<Schema>;
A more natural return type would be one that encapsulates functional errors, for example
getSchemaId(schema: SchemaDescription, options?: GetSchemaIdOptions): Promise<SchemaId | null>;
getSchemaById(id: string, options?: GetSchemaByIdOptions): Promise<Schema | null>;
Describe alternatives you’ve considered
A return type like Promise<Schema | { error: 'notfound', content: '...' }>
is more informative, but would not work with the widely used error handling patterns in Javascript like
const id = getSchemaById(...)
if(!id) {
...
}
If breaking backwards compatibility is not desired, I’d settle for having a fixed and documented behaviour about how one should check for this error, for example by ensuring the resulting Error
in the rejected promise will always have a { statusCode: 404 }
field like it does now.
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (5 by maintainers)
Top GitHub Comments
#15149 is out for review with that approach
FWIW text analytics has a “NotFound” code for their custom error shape: https://github.com/Azure/azure-sdk-for-js/blob/887eb013a7c9278b7eedb2c04c5e1bac0b984ebe/sdk/textanalytics/ai-text-analytics/review/ai-text-analytics.api.md