Skip to main content

Error Handling

The API uses a centralized error handling mechanism via GlobalExceptionHandler. All errors follow a consistent response format.

Error Response Format

{
"success": false,
"error": {
"code": "ERROR_CODE",
"message": "Human-readable error description",
"details": { ... }
}
}

HTTP Status Codes

Status CodeDescriptionWhen Used
200 OKSuccessSuccessful GET, PUT, DELETE operations
201 CreatedResource createdSuccessful POST operations
204 No ContentSuccess, no bodySome DELETE and action endpoints
400 Bad RequestInvalid requestValidation errors, bad input
401 UnauthorizedNot authenticatedMissing or invalid JWT token
403 ForbiddenAccess deniedInsufficient role/permissions
404 Not FoundResource not foundEntity doesn't exist
500 Internal Server ErrorServer errorUnexpected server errors

Exception Types

BadRequestException

Thrown when the request is malformed or contains invalid data.

{
"success": false,
"error": {
"code": "BAD_REQUEST",
"message": "Title must be less than 500 characters"
}
}

UnauthorizedException

Thrown when authentication fails.

{
"success": false,
"error": {
"code": "UNAUTHORIZED",
"message": "Invalid or expired token"
}
}

AccessDeniedException

Thrown when the user lacks required permissions.

{
"success": false,
"error": {
"code": "ACCESS_DENIED",
"message": "You do not have permission to perform this action"
}
}

ResourceNotFoundException

Thrown when the requested resource doesn't exist.

{
"success": false,
"error": {
"code": "NOT_FOUND",
"message": "Document not found with id: 550e8400-..."
}
}

BusinessException

Thrown for business logic violations.

{
"success": false,
"error": {
"code": "BUSINESS_ERROR",
"message": "Cannot transfer ownership to a non-member"
}
}

Validation Errors

When request body validation fails (JSR 380 / Jakarta Validation), the response includes field-level details:

{
"success": false,
"error": {
"code": "VALIDATION_ERROR",
"message": "Validation failed",
"details": {
"name": "Name is required",
"email": "Invalid email format"
}
}
}

Common Error Scenarios

ScenarioStatusCode
Invalid JWT token401UNAUTHORIZED
Token expired401UNAUTHORIZED
User not a workspace member403ACCESS_DENIED
Viewer tries to edit403ACCESS_DENIED
Document not found404NOT_FOUND
Workspace not found404NOT_FOUND
Duplicate invitation400BAD_REQUEST
Owner tries to leave workspace400BUSINESS_ERROR
Invalid export format400BAD_REQUEST
File upload too large400BAD_REQUEST