frontend
frontend copied to clipboard
Change `request` error message options type to a map of status codes
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;
};
// ...
};