Azure / Azure/data-api-builder

Allow custom exceptions in production mode

オープン
#2,222 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る
enhancement usability
主要言語
C#
スター
1.5k
フォーク
370
平均マージ
3日 22時間
マージ済み PR(30日)
9

説明

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](https://github.com/Azure/data-api-builder/blob/f996f10553096e389a2421abe0a98f0327d4435e/src/Core/Resolvers/DbExceptionParser.cs#L44C13-L44C88)

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](https://github.com/Azure/data-api-builder/blob/main/src/Core/Resolvers/MsSqlDbExceptionParser.cs)

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

コントリビューションガイド

コントリビューションガイドを開く

調査の方向性

src/Core/Resolvers/DbExceptionParser.cs から始め、src/Core/Resolvers/MsSqlDbExceptionParser.cs のプロバイダー固有の処理を、特に既存の例外コードグループに注目して比較します。user-exception コードの範囲または構成オプションによって、production で選択した stored-procedure メッセージを保持しつつ、その他のコードについては現在の処理を維持する方法を判断します。関連するパーサー全体で動作と選択した構成が一貫して定義されていれば完了です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
csharp, sql
領域
api, backend-api-design, databases
issue の種類
機能追加
難易度
5/5
見積もり時間
1週間以上
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
35/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。