While exploring the possibilities of using tsoa
for designing a rest API, I encountered an issue with the post
request that always leads to the following error message:
AssertionError [ERR_ASSERTION]: status code must be a number
at Object.set status [as status] (PROJECT_PATH/node_modules/koa/lib/response.js:87:5)
at Object.status (PROJECT_PATH/node_modules/delegates/index.js:92:31)
at Object.<anonymous> (PROJECT_PATH/src/rest/routes.ts:93:31)
at Generator.next (<anonymous>)
at PROJECT_PATH/src/rest/routes.ts:8:71
at new Promise (<anonymous>)
at __awaiter (PROJECT_PATH/src/rest/routes.ts:4:12)
at RegisterRoutes.router.post (PROJECT_PATH/src/rest/routes.ts:84:43)
at dispatch (PROJECT_PATH/node_modules/koa-compose/index.js:42:32)
at PROJECT_PATH/node_modules/koa-router/lib/router.js:353:16
The sample code segment causing this issue is as follows:
@Post()
public async createUser(@BodyProp() requestBody: UserInput): Promise<void> {
console.log(requestBody)
// code
this.setStatus(201);
return Promise.resolve();
}
In my configuration within the tsoa.json
file, I included "middleware": "koa",
since I am utilizing kao
.