-
-
Notifications
You must be signed in to change notification settings - Fork 321
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Define common error structure #560
Comments
@pavish Any 500 errors you encounter are bugs, please create individual issues for each 500 error you encounter. Thanks! |
I bumped into today and would like to help move this issue towards completion. As I see it, we can close this issue once we've agreed upon a standard behavior for API error responses. We would then use subsequent tickets to track the work of transforming specific API endpoints into conformance with that structure. I'd like to propose the following: API Error Response Behavior
@kgodey @pavish @mathemancer Can you either approve or suggest changes to the above? Once we're in agreement, I'll document our decision on the wiki. Having a decision here will help me with some of the front end work I'm doing, and it will allow me to begin reporting issues as I notice APIs which don't meet the standards. |
I think we should additionally have a mathesar-specific (maybe optional) error code (beyond the HTTP status code). This will help mapping DB-layer problems to more user-friendly error messages without string parsing, and enable custom error message generation logic in the front end if desired. |
I have lots of thoughts and this is in my queue but I might not get to it for a couple of days. |
I put a proposed structure and standards for API error handling in the API standards page based on @seancolsen and @mathemancer's ideas and some of my own. @dmos62 @mathemancer @pavish @seancolsen @silentninja Please review and leave feedback here, unassign when done (or if you have no feedback). Feel free to also edit the wiki page for clarity if needed. |
@kgodey I made some small edits for clarity. Suggested changes:
|
I like the spec. Have a few suggestions
At this point, I am not really sure if we really need a custom list as it would make a tight coupling with the frontend, we should rather be relying on the
I agree with @seancolsen that the error response should be a list always. I also agree with @pavish that any error specific detail such as |
I'd prefer to maintain our own set of error codes. From my perspective, one use of the error code is to allow the front end to perform custom actions depending on the specific error. Say a request has two failure modes. In mode A I want to perform a special action, and in mode B I don't. I'd like to rely on the error code for that control flow logic so that changes to the message don't break things. So with that reliance, yes, the front end would become somewhat more tightly coupled with the back end vs a case where we had no error codes -- but I think it will be useful in certain scenarios. That coupling implies the need to maintain strict immutability of error codes in the long-term. Once we've used a code, we want to make sure we don't change it or use it for some other purpose. That immutability means that we'll be expending error codes somewhat regularly as our codebase grows -- like an auto incrementing ID as we add and delete records. I'm not seeing a clean way to extend upon the HTTP status codes while satisfying the above goal of having somewhat infinite pool of "expendable" error codes. All of these errors should be 4xx error, if we're to adhere to the semantics within the HTTP spec. Many of the codes in the 4xx block already have their own designated meaning. That leaves us with a pretty limited number of codes to assign for our own purpose, and I think we're going to want to assign highly specific meaning to each of these codes. |
I am not opposed to it entirely, just trying to avoid it If possible. Do you have any specific API or scenario that we could use as an example? |
I like the idea of accurate HTTP status codes (4xx for bad input; 5xx for serverside bugs) and then a JSON The
Are there situations where we can catch multiple errors at once on the backend? |
Validation errors can return multiple error objects. |
@silentninja For an example of error codes, imagine that you're updating the type of a column. You might run into a variety of errors: These will all return a |
@dmos62 @mathemancer @pavish @seancolsen @silentninja Thanks for all your feedback. I've updated the spec, you can see the diff in the wiki page's History. Major changes:
{
"message": "This is an error message.",
"error_code": "2045",
"field": "name",
"details": {"failed_ids": [1, 2, 3, 4]}
} Reasoning:
Please leave feedback on this issue or unassign yourself if it looks good. |
Most of my concerns have been covered, except that I think
We can insert Foreign key constraints can also be multi-column, of course, but it presents less of a problem. |
The reason I prefer to have |
Seconded that By the way, why not |
@mathemancer @silentninja @dmos62 I was thinking about For example, imagine a request to rename and alter the type of a column via a PATCH request to {
'name': 'Topping',
'type': 'FOOD'
} The error response could be: [{
"message": "There is already a column with the same name.",
"error_code": "1010",
"field": "name",
"details": null,
}, {
"message": "FOOD is not a valid type.",
"error_code": "2001",
"field": "type",
"details": {
"available_types": ["INTEGER", "DECIMAL", "VARCHAR"]
}
} Does that make sense and does that change your feedback at all? Perhaps it would be clearer if I renamed |
Aha, I was completely misunderstanding. So in my example with the multi-column constraint, the columns list would be in the details. If that's correct (i.e., that |
I had misunderstood what |
@kgodey's last message makes sense so I'm inclined to go with her approach. If we run into situations on the front end that are difficult we can re-evaluate as-needed. I'm confident that Kriti's spec is going to good enough for quite a while, and I'd like to get going on implementing it. |
The idea behind As @seancolsen mentioned, we can always reevaluate the spec if needed. The most important thing at the moment is to have a consistent error standard. |
I'm closing this issue. I've opened a new one for implementation: #883 |
Description
Currently, there is no common error structure on the backend.
detail
Expected behaviour
The text was updated successfully, but these errors were encountered: