Creating personalized HTTP status codes within tsoa or any other similar framework

I was able to define custom status codes (such as 600) with TSOA in the past (v3.5.2), but it seems like the latest versions don't support this anymore. Considering that TSOA follows the OpenAPI specification, which only allows certain status codes listed here, this change is unexpected.

When attempting to use different status codes with decorators like

@Response<IErrorDomain>('600', 'Custom Error')
, I encountered an error during the build process:
Argument of type '"600"' is not assignable to parameter of type 'HttpStatusCodeLiteral | HttpStatusCodeStringLiteral | OtherValidOpenApiHttpStatusCode'

Is there a way to easily achieve this with the current versions of TSOA? If not, are there any alternatives to TSOA that allow for generating swagger documentation from express endpoints while supporting custom status codes?

Appreciate any guidance on this matter.

Answer №1

Avoid returning non-standard error codes that fall outside the accepted range of universal http error codes. This undermines the purpose of having standardized error codes. If you cannot find a suitable code for your situation, consider using codes in the 4XX or 5XX range (2XX are typically successes, 3XX indicate further action needed). You can define a custom error response like:

@Response<IErrorDomain>('4XX', 'Custom Error')

Instead of repurposing http error codes, create your own application-specific codes for better clarity.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

A clearly defined function is being mistakenly labeled as undefined

I am currently working on developing a user-friendly link-sharing web application using NodeJS and AngularJS. However, I have encountered an issue where a function is being identified as undefined. Take a look at the specific code snippet related to this ...

Generating a dynamic optional parameter for deduced generics

I have a specific object with the following structure: { first: (state: S, payload: boolean) => { payload: boolean, type: string }, second: (state: S) => { payload: undefined, type: string }, } My goal is to manipulate this object by removing th ...

Encountering an error when attempting to iterate over an undefined property using an API

I am trying to fetch all classes and their assignments from Google Classroom. I successfully used Google's example code for listing the classes, but had to write my own code for listing the assignments. While the code runs as expected and lists the as ...

Creating objects with nested objects in Express using Async: A step-by-step guide

Looking to create an object called user with sub-objects (authData, nameData, and emailData) in a synchronous manner has been successful. As an exercise, I wanted to explore implementing this using async. However, I am struggling with the syntax required f ...

Tips for ensuring that BingMaps is fully loaded in Aurelia

I have been attempting to integrate BingMaps into an Aurelia Single Page Application (SPA). My approach involved adding the BingMaps script tag to the Head section of the Index page, like so: <head> <meta charset="utf-8"> <script ty ...

What could be causing TypeORM to create an additional column in the query

Why does this TypeORM query produce the following result? const result6 = await getConnection() .createQueryBuilder() .select('actor.name') .from(Actor,'actor') .innerJoin('actor.castings',&apos ...

A single search to locate all children linked by a single reference

Today I am facing a problem with my application. I am using Express, MongoDB with Mongoose for the back-end. I have a model with an ObjectId reference to its parent. I want to retrieve all documents that have this parent, but I am only getting the parent& ...

Using TypeScript generics to create reusable type definitions for reducers

I have a common reducer function that needs to be properly typed. Here's what I have come up with: export interface WithInvalidRows<T extends { [K in keyof T]: InvalidCell[] }> { invalidRows: T; } interface AddPayload<S extends WithInval ...

Steps to Deploying a Typescript Express Application on Azure App Services

As I work on deploying a Typescript express app in Azure app services, I encountered an error message when trying to access my app's URL: You do not have permission to view this directory or page. I followed the same deployment process that I typica ...

Strategies for sending arguments to a TypeScript function from an HTML document

When I fetch my list of users as a JSONArray, I want to display the data of each user when their name is clicked. However, I am encountering difficulty passing the user's ID into the function. <ng-container *ngFor = "let user of users"> ...

Why am I encountering difficulties with my property injection, as it is not injecting anything other than undefined

In my current TypeScript project utilizing inversify, I have set up a logger in my TYPES as TYPES.ILoggger. When I access the logger directly from my container, it functions as expected: import {ILogger} from "./interfaces/ILogger"; import {TYPES} from ". ...

Dedicated pages for individual items within a MEAN application

I'm currently developing an application using Node, Express, Mongoose, and Angular. I have successfully displayed all items on a single page. My next task is to create a separate page for each item from the database. To achieve this, I set up a route: ...

"Troubleshooting: Node.js encountering a path error while loading a JSON file with

I am organizing a collection of folders and files structured like this: viz |_ app.js // node application |_ public |_ css |_ bubblemap.css |_ images |_ nuts |_ nuts0.json |_ script ...

The endpoint /api/user does not allow POST requests

I'm currently testing a user registration route and encountering a "Cannot POST /api/user" error. Although I can successfully make a GET request using Postman, the issue arises when trying to make a POST request. Any help or guidance on pinpointing t ...

Angular: Triggering SelectedTabChange exclusively for tabs that have been rendered

Within an Angular material tab group, I have a collection of tabs where each one triggers the method setGridHeight in every individual component (tab). <mat-tab-group [dynamicHeight]="true" (selectedTabChange)='queue0.setGridHeight();queue1.setGri ...

Why does the error message "DeprecationWarning: 'originalKeywordKind' deprecated" keep popping up while I'm trying to compile my project?

Upon completing the compilation of my project, I encountered the error message provided below. What does this signify and what steps can I take to resolve it? - info Linting and checking validity of types DeprecationWarning: 'originalKeywordKind' ...

What could be the rationale behind the optional chaining operator not being fully compatible with a union of classes in TypeScript?

Imagine I have a combination of classes: type X = ClassA | ClassB | ClassC; Both ClassA and ClassC have a shared method called methodY. Why is it that I can't simply use the optional chaining operator to call for methodY? class ClassA { methodY ...

Sending an HTML form data to a Node.js server

I'm currently working on a simple project that involves creating a web form and sending it to node.js in order to save the information received. I've been following some YouTube tutorials (https://www.youtube.com/watch?v=rin7gb9kdpk), but I' ...

When data is passed to the form-data from Postman in an Express.js API, req.body may end up empty

When passing data to form-data in Postman, I notice that the req.body is empty. However, if I pass data to x-www-form-urlencoded, then I am able to retrieve the data in req.body within my ExpressJS server. Click here for an image demonstration app.js con ...

Executing NPM scripts in bin directory upon import

My TypeScript 4.8.4 library is being packaged with npm. Within my package.json, I have a "bin" section that includes several utility scripts for consumers of the package. "bin": { "generate-docs": "./docs/docs.py&qu ...