Skip to content

Commit

Permalink
simplify
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed Jul 7, 2024
1 parent a2d9b5b commit 7345ca7
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions src/error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,18 +117,16 @@ export function createError<DataT = unknown>(
err.data = input.data;
}

if (input.statusCode) {
const statusCode =
input.statusCode ??
input.status ??
(input?.cause as H3Error)?.statusCode ??
(input?.cause as { status?: number })?.status;

if (typeof statusCode === "number") {
err.statusCode = sanitizeStatusCode(input.statusCode, err.statusCode);
} else if (input.status) {
err.statusCode = sanitizeStatusCode(input.status, err.statusCode);
} else if (
typeof input.cause === "object" &&
input.cause &&
"statusCode" in input.cause &&
typeof input.cause.statusCode === "number"
) {
err.statusCode = sanitizeStatusCode(input.cause.statusCode, err.statusCode);
}

if (input.statusMessage) {
err.statusMessage = input.statusMessage;
} else if (input.statusText) {
Expand Down

0 comments on commit 7345ca7

Please sign in to comment.