Skip to content

Error Codes Reference

All error responses from the chat-service follow this format:

json
{
  "success": false,
  "error": {
    "code": "CHAT_CHANNEL_NOT_FOUND",
    "message": "Channel not found",
    "details": { "channelId": "abc-123" }
  },
  "requestId": "req_xyz",
  "statusCode": 404,
  "timestamp": "2026-04-03T12:00:00.000Z",
  "path": "/channels/abc-123"
}

The details field is optional and provides additional context depending on the error.


Error Codes by Category

Auth Errors

CodeHTTP StatusDescriptionWhen it occurs
CHAT_AUTH_FAILED401Authentication failedMissing or expired JWT token
CHAT_AUTH_TOKEN_INVALID401Token is invalidMalformed JWT, wrong signing key, or token cannot be decoded
CHAT_AUTH_FORBIDDEN403Access deniedUser lacks permission for the requested action

Example: CHAT_AUTH_FAILED

json
{
  "success": false,
  "error": {
    "code": "CHAT_AUTH_FAILED",
    "message": "Authentication failed"
  },
  "statusCode": 401,
  "timestamp": "2026-04-03T12:00:00.000Z",
  "path": "/channels"
}

Channel Errors

CodeHTTP StatusDescriptionWhen it occurs
CHAT_CHANNEL_NOT_FOUND404Channel does not existAccessing a deleted or non-existent channel
CHAT_CHANNEL_ALREADY_EXISTS409Channel already existsCreating a duplicate direct channel between the same two users
CHAT_CHANNEL_FROZEN403Channel is frozenAttempting to send a message in a frozen channel
CHAT_CHANNEL_MEMBER_LIMIT413Member limit exceededInviting members when the channel already has 100 members
CHAT_CHANNEL_PIN_LIMIT413Pin limit exceededPinning a message when 5 messages are already pinned

Example: CHAT_CHANNEL_MEMBER_LIMIT

json
{
  "success": false,
  "error": {
    "code": "CHAT_CHANNEL_MEMBER_LIMIT",
    "message": "Channel cannot have more than 100 members",
    "details": {
      "maxMembers": 100
    }
  },
  "statusCode": 413,
  "timestamp": "2026-04-03T12:00:00.000Z",
  "path": "/channels/ch_abc/members/invite"
}

Example: CHAT_CHANNEL_PIN_LIMIT

json
{
  "success": false,
  "error": {
    "code": "CHAT_CHANNEL_PIN_LIMIT",
    "message": "Cannot pin more than 5 messages",
    "details": {
      "maxPinned": 5
    }
  },
  "statusCode": 413,
  "timestamp": "2026-04-03T12:00:00.000Z",
  "path": "/channels/ch_abc/messages/msg_xyz/pin"
}

Member Errors

CodeHTTP StatusDescriptionWhen it occurs
CHAT_NOT_CHANNEL_MEMBER403Not a channel memberAccessing a channel you are not a member of
CHAT_NOT_CHANNEL_OPERATOR403Not a channel operatorPerforming an operator-only action (ban, mute, invite, update, etc.)
CHAT_ALREADY_CHANNEL_MEMBER409Already a memberInviting a user who is already in the channel
CHAT_USER_MUTED403User is mutedAttempting to send a message while muted in the channel
CHAT_USER_BANNED403User is bannedAttempting any action while banned from the channel

Example: CHAT_NOT_CHANNEL_OPERATOR

json
{
  "success": false,
  "error": {
    "code": "CHAT_NOT_CHANNEL_OPERATOR",
    "message": "Only channel operators can perform this action"
  },
  "statusCode": 403,
  "timestamp": "2026-04-03T12:00:00.000Z",
  "path": "/channels/ch_abc/freeze"
}

Example: CHAT_USER_MUTED

json
{
  "success": false,
  "error": {
    "code": "CHAT_USER_MUTED",
    "message": "You are muted in this channel"
  },
  "statusCode": 403,
  "timestamp": "2026-04-03T12:00:00.000Z",
  "path": "/channels/ch_abc/messages"
}

Message Errors

CodeHTTP StatusDescriptionWhen it occurs
CHAT_MESSAGE_NOT_FOUND404Message does not existAccessing a deleted or non-existent message
CHAT_MESSAGE_NOT_OWNER403Not the message ownerEditing or deleting another user's message
CHAT_MESSAGE_TOO_LONG400Message exceeds max lengthSending or editing a message longer than 5000 characters

Example: CHAT_MESSAGE_NOT_FOUND

json
{
  "success": false,
  "error": {
    "code": "CHAT_MESSAGE_NOT_FOUND",
    "message": "Message not found",
    "details": {
      "messageId": "msg_nonexistent"
    }
  },
  "statusCode": 404,
  "timestamp": "2026-04-03T12:00:00.000Z",
  "path": "/channels/ch_abc/messages/msg_nonexistent"
}

Poll Errors

CodeHTTP StatusDescriptionWhen it occurs
CHAT_POLL_NOT_FOUND404Poll does not existAccessing a non-existent poll
CHAT_POLL_CLOSED410Poll is closedVoting on a poll that has been closed or expired
CHAT_POLL_OPTION_LIMIT400Too many optionsCreating a poll with more than 10 options
CHAT_POLL_ALREADY_VOTED409Already votedVoting again on a single-vote poll

Example: CHAT_POLL_CLOSED

json
{
  "success": false,
  "error": {
    "code": "CHAT_POLL_CLOSED",
    "message": "Poll is closed"
  },
  "statusCode": 410,
  "timestamp": "2026-04-03T12:00:00.000Z",
  "path": "/channels/ch_abc/polls/poll_xyz/vote"
}

Scheduled Message Errors

CodeHTTP StatusDescriptionWhen it occurs
CHAT_SCHEDULED_NOT_FOUND404Scheduled message not foundAccessing a non-existent scheduled message
CHAT_SCHEDULED_ALREADY_SENT410Already sentUpdating, canceling, or sending a scheduled message that was already dispatched
CHAT_SCHEDULED_INVALID_TIME400Invalid scheduled timeSetting scheduledAt to a time in the past

Example: CHAT_SCHEDULED_ALREADY_SENT

json
{
  "success": false,
  "error": {
    "code": "CHAT_SCHEDULED_ALREADY_SENT",
    "message": "Scheduled message has already been sent"
  },
  "statusCode": 410,
  "timestamp": "2026-04-03T12:00:00.000Z",
  "path": "/channels/ch_abc/scheduled-messages/sch_xyz/send-now"
}

User Errors

CodeHTTP StatusDescriptionWhen it occurs
CHAT_USER_NOT_FOUND404User does not existLooking up a non-existent user ID
CHAT_USER_ALREADY_BLOCKED409User already blockedBlocking a user who is already blocked

Example: CHAT_USER_ALREADY_BLOCKED

json
{
  "success": false,
  "error": {
    "code": "CHAT_USER_ALREADY_BLOCKED",
    "message": "User is already blocked"
  },
  "statusCode": 409,
  "timestamp": "2026-04-03T12:00:00.000Z",
  "path": "/users/block"
}

Storage Errors

CodeHTTP StatusDescriptionWhen it occurs
CHAT_FILE_TOO_LARGE400File exceeds size limitUploading a file larger than 25MB
CHAT_FILE_TYPE_NOT_ALLOWED400File type not permittedUploading a file with a disallowed MIME type
CHAT_UPLOAD_FAILED500Upload failedInternal storage error during file upload

Example: CHAT_FILE_TOO_LARGE

json
{
  "success": false,
  "error": {
    "code": "CHAT_FILE_TOO_LARGE",
    "message": "File exceeds maximum size of 25MB",
    "details": {
      "maxFileSize": 26214400
    }
  },
  "statusCode": 400,
  "timestamp": "2026-04-03T12:00:00.000Z",
  "path": "/channels/ch_abc/messages"
}

Generic Errors

CodeHTTP StatusDescriptionWhen it occurs
CHAT_VALIDATION_ERROR400Validation failedRequest body fails DTO validation, Prisma validation, or foreign key constraint
CHAT_CONFLICT409ConflictUnique constraint violation (e.g., duplicate reaction, duplicate block)
CHAT_INTERNAL_ERROR500Internal server errorUnexpected server error or database connection failure
CHAT_RATE_LIMITED429Rate limit exceededToo many requests from the same client

Example: CHAT_VALIDATION_ERROR

json
{
  "success": false,
  "error": {
    "code": "CHAT_VALIDATION_ERROR",
    "message": "text must be shorter than or equal to 5000 characters; text should not be empty",
    "details": {
      "validationErrors": [
        "text must be shorter than or equal to 5000 characters",
        "text should not be empty"
      ]
    }
  },
  "statusCode": 400,
  "timestamp": "2026-04-03T12:00:00.000Z",
  "path": "/channels/ch_abc/messages"
}

Example: CHAT_CONFLICT

json
{
  "success": false,
  "error": {
    "code": "CHAT_CONFLICT",
    "message": "Duplicate value for channelId, userId",
    "details": {
      "fields": ["channelId", "userId"]
    }
  },
  "statusCode": 409,
  "timestamp": "2026-04-03T12:00:00.000Z",
  "path": "/channels/ch_abc/members/invite"
}

Complete Error Code Table

#CodeHTTP StatusCategory
1CHAT_AUTH_FAILED401Auth
2CHAT_AUTH_TOKEN_INVALID401Auth
3CHAT_AUTH_FORBIDDEN403Auth
4CHAT_CHANNEL_NOT_FOUND404Channel
5CHAT_CHANNEL_ALREADY_EXISTS409Channel
6CHAT_CHANNEL_FROZEN403Channel
7CHAT_CHANNEL_MEMBER_LIMIT413Channel
8CHAT_CHANNEL_PIN_LIMIT413Channel
9CHAT_NOT_CHANNEL_MEMBER403Member
10CHAT_NOT_CHANNEL_OPERATOR403Member
11CHAT_ALREADY_CHANNEL_MEMBER409Member
12CHAT_USER_MUTED403Member
13CHAT_USER_BANNED403Member
14CHAT_MESSAGE_NOT_FOUND404Message
15CHAT_MESSAGE_NOT_OWNER403Message
16CHAT_MESSAGE_TOO_LONG400Message
17CHAT_POLL_NOT_FOUND404Poll
18CHAT_POLL_CLOSED410Poll
19CHAT_POLL_OPTION_LIMIT400Poll
20CHAT_POLL_ALREADY_VOTED409Poll
21CHAT_SCHEDULED_NOT_FOUND404Scheduled
22CHAT_SCHEDULED_ALREADY_SENT410Scheduled
23CHAT_SCHEDULED_INVALID_TIME400Scheduled
24CHAT_USER_NOT_FOUND404User
25CHAT_USER_ALREADY_BLOCKED409User
26CHAT_FILE_TOO_LARGE400Storage
27CHAT_FILE_TYPE_NOT_ALLOWED400Storage
28CHAT_UPLOAD_FAILED500Storage
29CHAT_VALIDATION_ERROR400Generic
30CHAT_CONFLICT409Generic
31CHAT_INTERNAL_ERROR500Generic
32CHAT_RATE_LIMITED429Generic

Prisma Error Mapping

Database-level errors from Prisma are automatically mapped to chat error codes:

Prisma CodeChat Error CodeHTTP StatusDescription
P2002CHAT_CONFLICT409Unique constraint violation
P2025CHAT_CHANNEL_NOT_FOUND404Record not found
P2003CHAT_VALIDATION_ERROR400Foreign key constraint failure
P2014CHAT_VALIDATION_ERROR400Required relation violation
OtherCHAT_INTERNAL_ERROR500Unhandled database error

MIT License