Azure / Azure/data-api-builder

Allow custom exceptions in production mode

Đang mở
#2,222 0 bình luận 0 reaction 0 người được giao Xem trên GitHub
enhancement usability
Ngôn ngữ chính
C#
Star
1.5k
Fork
370
Merge trung bình
3 ngày 22 giờ
Pull request đã merge (30 ngày)
9

Mô tả

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.

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Hướng nghiên cứu

Bắt đầu với src/Core/Resolvers/DbExceptionParser.cs và so sánh cách xử lý dành riêng cho provider trong src/Core/Resolvers/MsSqlDbExceptionParser.cs, đặc biệt là các nhóm mã exception hiện có. Xác định cách một khoảng mã user-exception hoặc một tùy chọn cấu hình nên giữ lại các thông báo stored-procedure được chọn trong production, đồng thời duy trì cách xử lý hiện tại cho các mã khác; được xem là hoàn tất khi hành vi và cấu hình được chọn được định nghĩa nhất quán giữa các parser liên quan.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
csharp, sql
Lĩnh vực
api, backend-api-design, databases
Loại issue
Tính năng
Độ khó
5/5
Thời gian dự kiến
Hơn một tuần
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Khá rõ ràng
Mức phù hợp với người mới
35/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.