Overview
The Juadah API uses a consistent error response format across all endpoints. Understanding this format will help you build robust error handling in your applications.Error Response Format
All error responses follow this structure:Response Fields
Always
"fail" for error responses. Success responses use "success".Container for error information.
HTTP Status Codes
The API uses standard HTTP status codes to indicate the type of error:400 - Bad Request
Invalid request due to validation errors or malformed data
404 - Not Found
The requested resource does not exist
500 - Internal Server Error
Something went wrong on the server side
Error Types
Validation Errors
Occur when request data doesn’t meet validation requirements. Example - Registration Validation Error:Email Validation
Email Validation
From
src/auth/schema.ts:4-6:"email is required"- Email field is missing"your email format is invalid"- Email format is incorrect
Password Validation
Password Validation
From
src/auth/schema.ts:8-10:"password is required"- Password field is missing"password and password confirmation is not match"- Passwords don’t match
Product Validation
Product Validation
"product name cannot be empty"- Name is required"product price cannot be empty"- Price is required"image extension is not supported"- Invalid file format"each product can only have 5 images at max"- Too many images
Authentication Errors
Occur when authentication credentials are invalid or missing.- Invalid Credentials
- Email Already Exists
- Invalid Refresh Token
Error: Incorrect email or password during loginTriggered by (
src/lib/Error.ts:1-5):Not Found Errors
Occur when a requested resource doesn’t exist.- Product ID doesn’t exist
- Order ID not found
- No products available
src/lib/Error.ts:13-19):
Bad Request Errors
Occur when the request is malformed or contains invalid data.src/lib/Error.ts:21-27):
Server Errors
Occur when something goes wrong on the server side.- Database connection failure
- External service unavailable
- Unexpected server errors
src/lib/Error.ts:29-35):
src/auth/service.ts:156-166):
Custom Validation Errors
Used for multipart form data validation (file uploads).src/lib/Error.ts:41-47):
Error Handling Examples
Best Practices
Always Check Status
Always verify the
status field before processing response data.Display Field-Specific Errors
Show validation errors next to their respective form fields.
Implement Retry Logic
Retry failed requests for server errors (500+) with exponential backoff.
Log Errors
Log errors for debugging, especially server errors.
Common Error Scenarios
User Registration
Possible Errors:
- Email validation error (invalid format)
- Email already exists
- Password too short
- Password mismatch
src/auth/schema.ts:13-28User Login
Possible Errors:
- Invalid credentials
- Missing email or password
- Server connection error
src/auth/service.ts:153-174Token Refresh
Possible Errors:
- Refresh token missing
- Refresh token expired
- Invalid refresh token
- Token not in database
src/auth/service.ts:177-231Next Steps
Authentication
Learn about authentication and token management
Rate Limits
Understand API usage limits
API Reference
Explore all available endpoints
Products API
Work with products