Skip to content

Commit

Permalink
Merge pull request #15 from jfrconley/joco/hotfix-error-content-type
Browse files Browse the repository at this point in the history
fix parse error content type
  • Loading branch information
jfrconley authored Dec 1, 2023
2 parents 1cb8832 + 668528f commit be4f584
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 8 deletions.
4 changes: 2 additions & 2 deletions packages/rest/__tests__/src/parse.spec.mts
Original file line number Diff line number Diff line change
@@ -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", () => {
Expand All @@ -14,6 +14,6 @@ describe("Parsing", () => {
rawQuery: ""
}

expect(() => parser(event)).toThrow(NornirParseError)
expect(() => parser(event)).toThrow(NornirRestParseError)
})
})
2 changes: 1 addition & 1 deletion packages/rest/src/runtime/index.mts
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
8 changes: 3 additions & 5 deletions packages/rest/src/runtime/parse.mts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export type HttpBodyParser = (body: Buffer) => unknown

export type HttpBodyParserMap = Partial<Record<MimeType | "default", HttpBodyParser>>

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;
Expand All @@ -21,9 +21,7 @@ export class NornirParseError extends NornirRestError {
headers: {
"content-type": MimeType.TextPlain,
},
body: {
message: this.message,
}
body: this.message
}
}
}
Expand Down Expand Up @@ -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)
}
}
}

0 comments on commit be4f584

Please sign in to comment.