From 668528fd1b9a2841c50abf73802918895a76741a Mon Sep 17 00:00:00 2001 From: John Conley <8932043+jfrconley@users.noreply.github.com> Date: Fri, 1 Dec 2023 14:30:10 -0800 Subject: [PATCH] fix parse error content type --- packages/rest/__tests__/src/parse.spec.mts | 4 ++-- packages/rest/src/runtime/index.mts | 2 +- packages/rest/src/runtime/parse.mts | 8 +++----- 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/packages/rest/__tests__/src/parse.spec.mts b/packages/rest/__tests__/src/parse.spec.mts index 73c77b1..93cc749 100644 --- a/packages/rest/__tests__/src/parse.spec.mts +++ b/packages/rest/__tests__/src/parse.spec.mts @@ -1,4 +1,4 @@ -import {httpEventParser, NornirParseError, UnparsedHttpEvent} from "../../dist/runtime/index.mjs"; +import {httpEventParser, NornirRestParseError, UnparsedHttpEvent} from "../../dist/runtime/index.mjs"; describe("Parsing", () => { it("Should throw correct error on failure to parse", () => { @@ -14,6 +14,6 @@ describe("Parsing", () => { rawQuery: "" } - expect(() => parser(event)).toThrow(NornirParseError) + expect(() => parser(event)).toThrow(NornirRestParseError) }) }) diff --git a/packages/rest/src/runtime/index.mts b/packages/rest/src/runtime/index.mts index 9e13937..5539600 100644 --- a/packages/rest/src/runtime/index.mts +++ b/packages/rest/src/runtime/index.mts @@ -12,7 +12,7 @@ export { export {RouteHolder, NornirRestRequestValidationError} from './route-holder.mjs' export {NornirRestRequestError, NornirRestError, httpErrorHandler, mapError, mapErrorClass} from './error.mjs' export {ApiGatewayProxyV2, startLocalServer} from "./converters.mjs" -export {httpEventParser, HttpBodyParser, HttpBodyParserMap, HttpQueryStringParser, NornirParseError} from "./parse.mjs" +export {httpEventParser, HttpBodyParser, HttpBodyParserMap, HttpQueryStringParser, NornirRestParseError} from "./parse.mjs" export {httpResponseSerializer, HttpBodySerializer, HttpBodySerializerMap} from "./serialize.mjs" export {normalizeEventHeaders, normalizeHeaders, getContentType} from "./utils.mjs" export {Router} from "./router.mjs" diff --git a/packages/rest/src/runtime/parse.mts b/packages/rest/src/runtime/parse.mts index 992489a..de0c646 100644 --- a/packages/rest/src/runtime/parse.mts +++ b/packages/rest/src/runtime/parse.mts @@ -9,7 +9,7 @@ export type HttpBodyParser = (body: Buffer) => unknown export type HttpBodyParserMap = Partial> -export class NornirParseError extends NornirRestError { +export class NornirRestParseError extends NornirRestError { constructor(cause: Error) { super("Failed to parse request. Bad content-type or invalid body", cause) this.cause = cause; @@ -21,9 +21,7 @@ export class NornirParseError extends NornirRestError { headers: { "content-type": MimeType.TextPlain, }, - body: { - message: this.message, - } + body: this.message } } } @@ -51,7 +49,7 @@ export function httpEventParser(bodyParserMap?: HttpBodyParserMap, queryStringPa query: queryStringParser(event.rawQuery), } } catch (error) { - throw new NornirParseError(error as Error) + throw new NornirRestParseError(error as Error) } } }