@dooboostore/simple-boot-http-server 1.0.31 → 1.0.32

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dooboostore/simple-boot-http-server",
3
- "version": "1.0.31",
3
+ "version": "1.0.32",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "main": "./dist/cjs/index.js",
@@ -101,8 +101,8 @@
101
101
  "@dooboostore/core": "1.0.33",
102
102
  "@dooboostore/dom-render": "1.0.115",
103
103
  "@dooboostore/core-node": "1.0.14",
104
- "@dooboostore/simple-boot": "1.0.59",
105
- "@dooboostore/core-web": "1.0.14"
104
+ "@dooboostore/core-web": "1.0.14",
105
+ "@dooboostore/simple-boot": "1.0.60"
106
106
  },
107
107
  "scripts": {
108
108
  "clean": "rm -rf dist",
@@ -22,6 +22,7 @@ import { FileUtils } from '@dooboostore/core-node';
22
22
  import { ConvertUtils as CoreConvertUtils } from '@dooboostore/core';
23
23
  import { ConvertUtils } from '@dooboostore/core-node';
24
24
  import {HttpMethod} from "../codes";
25
+ import { BadRequestError } from '../errors/BadRequestError';
25
26
 
26
27
  type Config = { sessionManager?: SessionManager; option: HttpServerOption };
27
28
 
@@ -346,7 +347,14 @@ export class RequestResponse {
346
347
  }
347
348
 
348
349
  async reqBodyJsonData<T>(): Promise<T> {
349
- return JSON.parse(await this.reqBodyStringData());
350
+ const raw = await this.reqBodyStringData();
351
+ try {
352
+ return JSON.parse(raw);
353
+ } catch (e: any) {
354
+ // Malformed JSON is a client error (400), not a server crash (500).
355
+ // Express-compatible: surface the parse failure as Bad Request.
356
+ throw new BadRequestError({ message: `Invalid JSON body: ${e?.message ?? e}` });
357
+ }
350
358
  }
351
359
 
352
360
  async reqBodyFormUrlData<T>(): Promise<T> {
@@ -372,7 +380,15 @@ export class RequestResponse {
372
380
 
373
381
  async reqBodyReqJsonBody(): Promise<ReqJsonBody> {
374
382
  const data = await this.reqBodyStringData();
375
- return Object.assign(new ReqJsonBody(), data ? JSON.parse(data) : {});
383
+ if (!data) {
384
+ return Object.assign(new ReqJsonBody(), {});
385
+ }
386
+ try {
387
+ return Object.assign(new ReqJsonBody(), JSON.parse(data));
388
+ } catch (e: any) {
389
+ // Malformed JSON is a client error (400), not a server crash (500).
390
+ throw new BadRequestError({ message: `Invalid JSON body: ${e?.message ?? e}` });
391
+ }
376
392
  }
377
393
 
378
394
  resBodyJsonData<T>(): T | null {
@@ -8,6 +8,7 @@ import { RequestResponse } from '../models/RequestResponse';
8
8
  import { SimpleBootHttpServer } from '../SimpleBootHttpServer';
9
9
  import { TransactionManager } from '@dooboostore/core';
10
10
  import { WebSocketEndPoint } from '../endpoints/WebSocketEndPoint';
11
+ import { NotFoundError } from '../errors/NotFoundError';
11
12
 
12
13
  export type Listen = { port?: number, hostname?: string, backlog?: number, listeningListener?: (server: SimpleBootHttpServer, httpServer: HttpServer | HttpsServer) => void };
13
14
 
@@ -107,7 +108,13 @@ export class HttpServerOption extends SimOption {
107
108
  );
108
109
  this.globalAdvice = globalAdvice;
109
110
  this.fileUploadTempPath = fileUploadTempPath;
110
- this.noSuchRouteEndPointMappingThrow = noSuchRouteEndPointMappingThrow;
111
+ // Unmatched routes must not fall through to "200 OK with empty body"
112
+ // like before. Default to 404 (Express-compatible); users can still
113
+ // override with their own noSuchRouteEndPointMappingThrow.
114
+ this.noSuchRouteEndPointMappingThrow =
115
+ noSuchRouteEndPointMappingThrow ??
116
+ ((rr: RequestResponse) =>
117
+ new NotFoundError({ message: `no route ${rr.reqMethod?.() ?? ''} ${rr.reqUrlPathName ?? ''}`.trim() }));
111
118
  this.transactionManagerFactory = transactionManagerFactory;
112
119
  }
113
120