-
Notifications
You must be signed in to change notification settings - Fork 12
kiit.codes
kishore edited this page May 26, 2026
·
5 revisions
Status is a platform-agnostic status type that lives in src/lib/codes/. It describes the status of any operation — a service call, a background job step, using a consistent shape rather than throwing raw errors or returning ad-hoc booleans.
Sample JSON representation, which can be used as ApiError response.
{
"name" : "TOKEN_EXPIRED",
"type" : "denied" // denied | ignored | invalid | errored | unknown
"code" : 403,
"success": false,
"message": "Session token expired"
}Logical heirarchy and relationship of the status types.
- Status = Passed | Failed
- Passed = Succeeded | Pending | Filtered | Ignored
- Failed = Denied | Invalid | Errored | Unknown
graph TD
classDef statusNode fill:#3b82f6,stroke:#1d4ed8,color:#ffffff,font-weight:bold
classDef passedNode fill:#86efac,stroke:#16a34a,color:#14532d,font-weight:bold
classDef succeededNode fill:#22c55e,stroke:#15803d,color:#ffffff,font-weight:bold
classDef pendingNode fill:#fde047,stroke:#ca8a04,color:#713f12,font-weight:bold
classDef filteredNode fill:#9ca3af,stroke:#6b7280,color:#ffffff,font-weight:bold
classDef ignoredNode fill:#9ca3af,stroke:#6b7280,color:#ffffff,font-weight:bold
classDef failedNode fill:#fca5a5,stroke:#f87171,color:#7f1d1d,font-weight:bold
classDef deniedNode fill:#111827,stroke:#000000,color:#ffffff,font-weight:bold
classDef invalidNode fill:#f97316,stroke:#c2410c,color:#ffffff,font-weight:bold
classDef erroredNode fill:#dc2626,stroke:#b91c1c,color:#ffffff,font-weight:bold
classDef unknownNode fill:#7f1d1d,stroke:#450a0a,color:#ffffff,font-weight:bold
Status["Status<br/>name / type / code<br/>message / success"]
Passed["Passed<br/>success: true"]
Failed["Failed<br/>success: false"]
Succeeded["Succeeded<br/>type: succeeded"]
Pending["Pending<br/>type: pending"]
Filtered["Filtered<br/>type: filtered"]
Ignored["Ignored<br/>type: ignored"]
Denied["Denied<br/>type: denied"]
Invalid["Invalid<br/>type: invalid"]
Errored["Errored<br/>type: errored"]
Unknown["Unknown<br/>type: unknown"]
Status --> Passed
Status --> Failed
Passed --> Succeeded
Passed --> Pending
Passed --> Filtered
Passed --> Ignored
Failed --> Denied
Failed --> Invalid
Failed --> Errored
Failed --> Unknown
class Status statusNode
class Passed passedNode
class Succeeded succeededNode
class Pending pendingNode
class Failed failedNode
class Denied deniedNode
class Ignored ignoredNode
class Invalid invalidNode
class Errored erroredNode
class Unknown unknownNode
Three problems this solves:
- Universal: Can be used universally in service layers ( XService.ts ), background jobs, routes.
- Hierarchy: Status has a logical group and heirarchy for successes and failures.
- Standard : Establishes an precise status type and representation across layers.
-
Compliant: Convertible to Http status codes via
toHttpStatus()insrc/lib/codes/utils.ts - Reusable : Can be reused across multiple operations that can yield the same status/error.
- Extensible: Easily extensible by creating new Status Codes for specific domains / features.
- Searchable: The name and type are unique and easily searchable in logs.
- Aggregated: Because of the hierarchy, the type, or name can be aggregated in logs/records.
-
Exceptions: Compatible with exceptions via the
StatusErrorsubtype of Error to store it.
Similar definitions exist else where.
GraphQL
The closest representation of this is MutationError
https://cosmo.wundergraph.com/4f7ac3fd/staging/graph/main/schema?category=interfaces&typename=MutationError&fieldName=
{
code: number,
message: string
}| Parent | Type | Level | Purpose |
|---|---|---|---|
| Status | Passed |
Parent | Parent of successes |
| Passed | Succeeded |
Child | Successful operation |
| Passed | Pending |
Child | Pending processing |
| Passed | Filtered |
Child | Filtered from processing |
| Passed | Ignored |
Child | Processed but ignored |
| Status | Failed |
Parent | Parent for any failure |
| Failed | Denied |
Child | Security related |
| Failed | Invalid |
Child | Invalid data |
| Failed | Errored |
Child | Failure of known business rule |
| Failed | Unknown |
Child | Unhandled failure |
Every Status has the following fields and carries the info:
| Field | Purpose |
|---|---|
type |
Discriminant of ('denied', 'invalid', 'ignored', 'errored', 'unknown', ) |
name |
Unique domain label of status, e.g. TOKEN_EXPIRED, RATE_LIMITED, both are Denied
|
code |
Numeric code — defaults align with HTTP status codes, flexible for other runtimes |
message |
Human-readable description — must be a constant, never constructed from runtime data |
success |
Boolean shortcut for callers that don't need to narrow the type |