The Ocha API communicates the outcome of every request through standard HTTP status codes. Errors originating from Mongoose validation or duplicate key constraints are normalized by theDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/floriansalvi/HEIG-VD_Ocha-api/llms.txt
Use this file to discover all available pages before exploring further.
utils/errorHandler.js utility before being sent to the client. The table below summarizes all codes, followed by detailed descriptions of when each one occurs and how to respond to it.
Status code summary
| Code | Name | Meaning |
|---|---|---|
| 200 | OK | Request succeeded; resource(s) returned in body |
| 201 | Created | New resource created; resource returned in body |
| 204 | No Content | Resource deleted; no body returned |
| 400 | Bad Request | Request is malformed or missing required data |
| 401 | Unauthorized | JWT token is missing, expired, or invalid |
| 403 | Forbidden | Authenticated, but the account lacks admin role |
| 404 | Not Found | Requested resource does not exist |
| 409 | Conflict | Unique constraint violated (duplicate key) |
| 422 | Unprocessable Entity | Request body failed Mongoose schema validation |
| 500 | Internal Server Error | Unexpected server-side error |
200 OK
The request was processed successfully and the response body contains the requested data. When it occursGETrequests that retrieve one or more resources (users, products, stores, orders, order items, order stats)PATCHrequests that update an existing resource
201 Created
A new resource was created successfully. The newly created document is returned in the response body. When it occursPOST /api/v1/auth— new user account registeredPOST /api/v1/products— new product created (admin)POST /api/v1/stores— new store created (admin)POST /api/v1/orders— new order placed by authenticated user
204 No Content
The resource was deleted successfully. The response body is empty. When it occursDELETE /api/v1/products/{productId}— product deleted (admin)DELETE /api/v1/stores/{storeId}— store deleted (admin)DELETE /api/v1/orders/{orderId}— order deleted
400 Bad Request
The request is malformed, missing required fields, or contains a value that cannot be understood by the server. When it occurs- Required body fields are absent (e.g., missing
pickupdate when creating an order) - A field value is of the wrong type before it reaches Mongoose validation
Example 400 response
401 Unauthorized
The request requires authentication, but no valid JWT was provided. When it occurs- The
Authorizationheader is absent on a protected route - The JWT has expired (tokens are valid for 7 days)
- The JWT signature is invalid
Authorization header using the Bearer scheme. Obtain a new token via POST /api/v1/auth/login if the current one has expired.
Example authorization header
403 Forbidden
The request is authenticated, but the account does not have theadmin role required for the endpoint.
When it occurs
- A
user-role account attempts to call an admin-only route (e.g., creating or deleting a product or store, reading order statistics)
404 Not Found
The requested resource does not exist in the database. When it occursGET /api/v1/products/{productId}— no product matches the given IDGET /api/v1/stores/{storeId}— no store matches the given IDGET /api/v1/orders/{orderId}— no order matches the given ID, or the order belongs to a different user
Example 404 response
409 Conflict
A unique constraint was violated. The resource you are trying to create or update would duplicate a field that must be unique. When it occurs- Registering a user with an
emailordisplay_namethat already exists (POST /api/v1/auth) - Creating a product with a
namethat already exists - Creating a store with a
nameoremailthat already exists
handleMongooseError when Mongoose reports error code 11000 (duplicate key).
What to do
Choose a different value for the conflicting field. The error message from the API will identify which field caused the conflict.
Example 409 response
422 Unprocessable Entity
The request body was received but failed Mongoose schema validation. The data is syntactically valid but semantically incorrect. When it occurs- A field value falls outside its allowed enum (e.g.,
size: "XL"instead ofS,M, orL) - A number is below its minimum (e.g.,
basePriceCHF: -1) - A string violates a length constraint (e.g., store
nameshorter than 3 characters) opening_hoursdoes not contain exactly 7 entries, or an entry is not[]or a valid["HH:MM", "HH:MM"]pairlocation.coordinatesdoes not contain exactly two valid numbers
handleMongooseError when Mongoose throws a ValidationError.
What to do
Read the error field in the response body for the specific validation message. Correct the offending field and resubmit.
Example 422 response
500 Internal Server Error
An unexpected error occurred on the server that was not handled by a more specific error path. When it occurs- A database connection failure
- An unhandled exception in a controller
- Any error that is not a Mongoose
ValidationErroror duplicate key error, caught byhandleMongooseError
Example 500 response