Errors
There are four kinds of failure. Handle them in one place (the HRMS.Mobile API client already does).
1. Validation error (HTTP 200, isSuccess: false, errorCode: 1)
The request was understood but refused: wrong password, outside the allowed date range, not allowed for this employee, and so on.
{
"isSuccess": false,
"responseData": null,
"errorCode": 1,
"errorMessage": "Thumb Application Limit Days Exceeded, You Can't Add This Entry",
"errorTitle": ""
}
Show errorMessage to the user as-is. The messages are written for users. Every endpoint page lists the messages that endpoint can return, taken from the server code.
responseData is the default value of the endpoint's type: null for objects, lists and strings, false for booleans, 0 for numbers.
2. Server error (HTTP 200, isSuccess: false, errorCode: 2)
Returned when a service caught an exception (ApiErrorResponse(ex)). errorMessage is the exception text, which is not user-friendly. Show a generic message ("Something went wrong") with a Try again button, and log the text.
3. HTTP 401 Unauthorized
No token, an invalid token, or an expired one (after 24 hours). There is no JSON body. Follow token expiry: silent re-login once, otherwise back to the login screen.
4. HTTP 500 and network errors
- HTTP 500: an exception that no service caught. The server has the developer exception page switched on in every environment, so the body is HTML or plain text, not JSON. Do not try to parse it; show the generic error.
- No response / timeout: show the offline or timeout message and keep cached data on screen.
Messages you will see on many endpoints
| Message | Meaning | What to do |
|---|---|---|
Thumb Application Limit Days Exceeded, You Can't Add This Entry | The employee has approved leave covering that date, or is inactive. Not a day-count limit. | "You are on approved leave on this date." |
Request Forbidden, Can't access proper Company. | The token has no company the record belongs to. | Usually a bad or old token. Log in again. |
You can't create or change applications for this employee. | The employeeId (or the stored record) is not you or your team. | Always send your own employeeId (team leaders: a team member's). See Server rules. |
This application is already approved or rejected. Only an approver can change it. | Saving with a non-Pending status, or editing a decided application, without approval rights. | Employees: save edits as Pending (status 0). |
You can't view or delete this application. | Get by id or delete for someone outside your team. | Hide the action. |
You can't approve or reject these applications. | Approve/reject by someone who is not Admin, or not the leader (with the tenant setting on), or for their own application. | Hide the approve buttons using the same rule. |
Recommended client mapping
| Case | ApiError.kind in HRMS.Mobile | UI |
|---|---|---|
isSuccess: false, errorCode: 1 | validation | Show errorMessage (toast or inline banner) |
isSuccess: false, errorCode: 2 | server | "Something went wrong" + retry |
| HTTP 401 after re-login failed | unauthorized | Back to login with "Your session expired" |
| HTTP 5xx | server | "Something went wrong" + retry |
| No response | network / timeout | Offline banner, keep cached data |