diff --git a/source/constants.ts b/source/constants.ts index 2e1c6f7..9eff4c8 100644 --- a/source/constants.ts +++ b/source/constants.ts @@ -1,3 +1,18 @@ +/** + * 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; + /** * HTTP status code for "Not Acceptable" error. */ 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, });