Add constants for status codes

This commit is contained in:
2026-08-03 03:13:30 +00:00
parent ee2280da50
commit e421d75960
2 changed files with 19 additions and 1 deletions
+17
View File
@@ -0,0 +1,17 @@
/**
* Success response status code.
*/
export const HTTP_STATUS_CODE_SUCCESS = 200;
/**
* Created response status code.
*/
export const HTTP_STATUS_CODE_CREATED = 201;
/**
* No content response status code.
*/
export const HTTP_STATUS_CODE_NO_CONTENT = 204;
+2 -1
View File
@@ -1,5 +1,6 @@
import type { RouteSendOptions, RouteStream } from '../routes/types.ts';
import type { BaseStream } from './stream/base-stream.ts';
import { HTTP_STATUS_CODE_NO_CONTENT, HTTP_STATUS_CODE_SUCCESS } from '../constants.ts';
/**
* Binds one application request to a connection-level stream.
@@ -44,7 +45,7 @@ export class ApplicationRouteStream implements RouteStream {
await this.connection.send({
...(this.requestId === undefined ? {} : { id: this.requestId }),
type,
statusCode: options.statusCode ?? (data === undefined ? 204 : 200),
statusCode: options.statusCode ?? (data === undefined ? HTTP_STATUS_CODE_NO_CONTENT : HTTP_STATUS_CODE_SUCCESS),
body: data ?? null,
});