Refactor API error handling to be more consistent#45
Merged
ScriptyChris merged 7 commits intodevelopfrom Nov 3, 2021
Merged
Conversation
…setting User password and setting a new one; Add regarding API endpoints and extend User schema to handle reset password token; Extend Mailer module to handle sending email with link to reset password;
…'api/users' middlewares error handling;
…I routes middlewares error handling;
…t frontend's ApiService and regarding components to conform to API error handling; Implement GenericErrorPopup component, which wraps Popup and subscribes to ApiService to handle each request error (can be disabled per API call) and exception;
… calls to ensure correct response schema; Remove unnecessary adHocUserUpdate.js module;
14 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Partially related to #22 (backend HTTP statuses unification).
add
HTTP_STATUS_CODEenum and use it instead of arbitrary number values inres.status(..)callsadd
middlewareErrorHandlerfunction to handle API exceptions (likely500error codes), which is called incatchstatement inside every middleware functionmake calls to response
jsonmethod more consistent. It now receives an object with either:msgproperty indicating success message,errorproperty indicating more context for failure message (like for400or401error codes)payloadobject property containing arbitrary data sent to clientexceptionobject containing some unexpected error (likely created bymiddlewareErrorHandler)More expected errors are now handled by sending back a meaningful
errormessage rather than giving back an500error.add
middleware-response-wrapperto ensure API responses have correct schemaadapt frontend's
ApiServiceto new API response schemaadd
GenericErrorPopupcomponent, which is called by every Ajax call, that automatically shows popup with generic error, when any Ajax/API related error happens. Although, there is an option to omit handling error if it's exactly theerrorand not some exception by callingapiService.disableGenericErrorHandler()(per single call, because it's automatically restored after the Ajax call itself) before the targetApiServicemethodadjust unit tests