From e421d75960f694091b27ab7ee7b2e82f429b31af Mon Sep 17 00:00:00 2001 From: Harvmaster Date: Mon, 3 Aug 2026 03:13:30 +0000 Subject: [PATCH] Add constants for status codes --- source/constants.ts | 17 +++++++++++++++++ source/services/route-stream.ts | 3 ++- 2 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 source/constants.ts diff --git a/source/constants.ts b/source/constants.ts new file mode 100644 index 0000000..140fe80 --- /dev/null +++ b/source/constants.ts @@ -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; + + + diff --git a/source/services/route-stream.ts b/source/services/route-stream.ts index 9c41221..e3b1b6c 100644 --- a/source/services/route-stream.ts +++ b/source/services/route-stream.ts @@ -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, });