Skip to main content

Errors

The ION Guard API uses standard HTTP status codes and returns error messages in a consistent JSON format.

Error response format

Simple error

{
"message": "Invalid credentials."
}

Validation error (422)

{
"message": "The given data was invalid.",
"errors": {
"email": ["O campo email é obrigatório."],
"password": ["A senha deve ter pelo menos 8 caracteres."]
}
}

The message field provides a readable summary (usually the first validation message) and the errors field is an object where each key is the field name and the value is an array with all error messages for that field. Always base error display on the errors object, not just on message.

Status codes

CodeMeaningWhen it occurs
200OKSuccessful request
201CreatedResource created successfully
204No ContentSuccessful operation with no response body
401UnauthorizedToken missing, invalid, or expired
403ForbiddenAuthenticated user without permission for the action
404Not FoundResource not found
422Unprocessable EntityValidation error in the submitted data
429Too Many RequestsRate limit exceeded — see Rate Limiting
500Server ErrorInternal server error

401 — Expired token

When you receive a 401, try refreshing the token via refresh. If the refresh also fails, redirect to login.

Request → 401 → POST /auth/refresh → New token → Retry request
→ 401 on refresh → Redirect to login

422 — Validation errors

Iterate over the errors object to display specific messages per field:

const response = await fetch('/api/v1/sites', { method: 'POST', body, headers });

if (response.status === 422) {
const { errors } = await response.json();
// errors.name → ["The name field is required."]
// errors.timezone → ["The selected timezone is invalid."]
}

429 — Rate limit

Wait the time indicated in the Retry-After header and retry the request:

if (response.status === 429) {
const retryAfter = response.headers.get('Retry-After');
await sleep(retryAfter * 1000);
// Retry request
}

500 — Server error

500 errors indicate a problem on the server. Do not retry the request immediately. If it persists, check the server logs or contact support.