Azure / data-api-builder

Data API builder provides modern REST and GraphQL endpoints to your Azure Databases and on-prem stores.
https://aka.ms/dab/docs
MIT License
787 stars 142 forks source link

Allow custom exceptions in production mode #2222

Open pholcroft opened 1 month ago

pholcroft commented 1 month ago

As a user of API's myself I really appreciate helpful messages explaining why the action failed. It really helps with development and maintenance. If a user complains an action hasn't worked, the error message can really help save a lot of time debugging.

Currently with DAB if an error is thrown by a stored procedure it will only be displayed in development mode only. Code

However I would like to display certain custom error messages to users of the API even in production mode.

Some examples I have in my SP's:

Currently there are the following exception types for MsSql although it's similar for the other parsers: Code

From the Code link, it's visible there is a hard coded list of exception code numbers which relate to each type.

Why not add in UserExceptionCodes? Then make an exception for those codes to keep the real error message.

Then we can simply add something like the below to return an error to the user of the API.

THROW 60001, 'LastName cannot be blank', 1;

Options to implement this:

  1. This could be error codes with a number >50000 in the case of MsSql (as these are kept for user exceptions).
  2. Hard code a small range of codes we can use, e.g. 60000-61000.
  3. Add this as an option to the configuration file to specify a range of codes to be used for user exceptions.