Skip to content

Refactor API error handling to be more consistent#45

Merged
ScriptyChris merged 7 commits intodevelopfrom
refactor/make-api-middlewares-error-handling-more-consistent
Nov 3, 2021
Merged

Refactor API error handling to be more consistent#45
ScriptyChris merged 7 commits intodevelopfrom
refactor/make-api-middlewares-error-handling-more-consistent

Conversation

@ScriptyChris
Copy link
Copy Markdown
Owner

@ScriptyChris ScriptyChris commented Nov 3, 2021

Partially related to #22 (backend HTTP statuses unification).

  • add HTTP_STATUS_CODE enum and use it instead of arbitrary number values in res.status(..) calls

  • add middlewareErrorHandler function to handle API exceptions (likely 500 error codes), which is called in catch statement inside every middleware function

  • make calls to response json method more consistent. It now receives an object with either:

    • msg property indicating success message,
    • error property indicating more context for failure message (like for 400 or 401 error codes)
    • payload object property containing arbitrary data sent to client
    • exception object containing some unexpected error (likely created by middlewareErrorHandler)

    More expected errors are now handled by sending back a meaningful error message rather than giving back an 500 error.

  • add middleware-response-wrapper to ensure API responses have correct schema

  • adapt frontend's ApiService to new API response schema

  • add GenericErrorPopup component, 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 the error and not some exception by calling apiService.disableGenericErrorHandler() (per single call, because it's automatically restored after the Ajax call itself) before the target ApiService method

  • adjust unit tests

…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;
…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;
@ScriptyChris ScriptyChris added the maintenance Actions related to building, testing, refactoring etc. that don't directly affect using app label Nov 3, 2021
… calls to ensure correct response schema; Remove unnecessary adHocUserUpdate.js module;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

maintenance Actions related to building, testing, refactoring etc. that don't directly affect using app

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant