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:
Duplicate Email Address, contacts must have unique email addresses.
ManagerId does not exist
LastName cannot be blank
FromDate is greater than last update of messages 2024-05-01
Invalid NominalCode for the Chart of Accounts
ManagerId does not have permission to access this client
Currently there are the following exception types for MsSql although it's similar for the other parsers: Code
BadRequestExceptionCodes
TransientExceptionCodes
ConflictExceptionCodes
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:
This could be error codes with a number >50000 in the case of MsSql (as these are kept for user exceptions).
Hard code a small range of codes we can use, e.g. 60000-61000.
Add this as an option to the configuration file to specify a range of codes to be used for user exceptions.
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: