frontend icon indicating copy to clipboard operation
frontend copied to clipboard

Change `request` error message options type to a map of status codes

Open RichDom2185 opened this issue 2 years ago • 5 comments

The current implementation is not flexible enough:

https://github.com/source-academy/frontend/tree/master/src/commons/utils/RequestHelper.tsx#L21-L28

This only allows for a catch-all, and therefore, generic error message when any errors occur. However, there are quite a number of use cases where we want to show differing error messages depending on the backend status code. For example:

  • 401/403 – straightforward
  • 409 Conflict - resource already exists
  • ... other potential error messages here

as a request can fail due to many reasons, not simply due to insufficient permissions.

Proposal:

Change errorMessage (when defined) from string to

type RequestOptions = {
  // ...
  errorMessage?: {
    [statusCode: number]: React.ReactNode;
  };
  // ...
};

RichDom2185 avatar Jul 27 '23 21:07 RichDom2185