Every response from the VidTube API — whether successful or not — follows a consistent JSON structure. This makes it straightforward to check outcomes programmatically: inspect theDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/Pragyat-Nikunj/VidTube/llms.txt
Use this file to discover all available pages before exploring further.
success field, read the message for a human-readable description, and act on the statusCode. Understanding this contract helps you write client code that handles both happy paths and failures without guessing at response shapes.
Success response format
Successful responses use theApiResponse class. The success field is true whenever statusCode is less than 400.
| Field | Type | Description |
|---|---|---|
statusCode | number | HTTP status code of the response. |
data | any | The response payload. Shape varies by endpoint. |
message | string | Human-readable description of the outcome. Defaults to "Success". |
success | boolean | true when statusCode < 400, false otherwise. |
statusCode is 201 and data contains the newly created object.
Error response format
Error responses use theApiError class. The success field is always false. In development (NODE_ENV !== "production"), the response also includes a stack field with the full Node.js stack trace to help with debugging.
| Field | Type | Description |
|---|---|---|
statusCode | number | HTTP status code of the error. |
data | null | Always null for errors. |
message | string | Human-readable error description. |
success | boolean | Always false for errors. |
errors | array | Additional error details, such as validation failures. Empty array if not applicable. |
stack | string | Stack trace. Only present when NODE_ENV is not "production". |
Stack traces are included in error responses only when the server is running with
NODE_ENV set to anything other than "production". In production, the stack field is omitted entirely, so you do not expose internal file paths or implementation details to callers.HTTP status codes
| Status | Meaning | Common causes in VidTube |
|---|---|---|
200 OK | Request succeeded. | Fetching a user, video, comments, or any read operation. |
201 Created | Resource was created. | Registering a user, publishing a video, creating a playlist or tweet. |
400 Bad Request | The request is malformed or missing required fields. | Missing required body fields, invalid MongoDB ObjectId format. |
401 Unauthorized | Authentication failed or no credentials provided. | No token, malformed token, expired access token, wrong password, invalid refresh token. |
404 Not Found | The requested resource does not exist. | User not found, video not found, channel not found. |
500 Internal Server Error | An unexpected error occurred on the server. | Cloudinary upload failed, JWT token generation failed, unhandled exception. |
Tips for callers
Always check thesuccess field first. Even if the HTTP status code is in the 2xx range, reading success confirms the API considers the operation successful.
Read message for context. The message field gives you a plain-language explanation of what happened, including for errors. This is more reliable than parsing the HTTP status code alone because VidTube may return the same status code for multiple distinct error conditions.
Handle 401 with token rotation in mind. When you receive a 401 on a protected endpoint after a period of inactivity, your access token has likely expired. Call POST /users/refresh-Token with your refresh token to obtain a new access token, then retry the original request. If the refresh also returns 401, the refresh token has expired and the user must log in again.
Expect an empty errors array on most errors. The errors array is populated for validation scenarios but is an empty array ([]) for most error types. Do not rely on it being non-empty to detect an error — use success: false instead.
Do not display stack to end users. The stack trace is a development aid. Strip it from any error output shown in a production UI.