Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions packages/kit/src/exports/internal/index.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
export class HttpError {
export class HttpError extends Error {
/**
* @param {number} status
* @param {{message: string} extends App.Error ? (App.Error | string | undefined) : App.Error} body
*/
constructor(status, body) {
const normalized =
typeof body === 'string' ? { message: body } : body ?? { message: `Error: ${status}` };

const message =
typeof normalized?.message === 'string' ? normalized.message : `Error: ${status}`;

super(message);

this.name = 'HttpError';
this.status = status;
if (typeof body === 'string') {
this.body = { message: body };
} else if (body) {
this.body = body;
} else {
this.body = { message: `Error: ${status}` };
}
this.body = normalized;
}

toString() {
Expand Down
2 changes: 1 addition & 1 deletion packages/kit/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2706,7 +2706,7 @@ declare module '@sveltejs/kit' {
export type LessThan<TNumber extends number, TArray extends any[] = []> = TNumber extends TArray["length"] ? TArray[number] : LessThan<TNumber, [...TArray, TArray["length"]]>;
export type NumericRange<TStart extends number, TEnd extends number> = Exclude<TEnd | LessThan<TEnd>, LessThan<TStart>>;
export const VERSION: string;
class HttpError_1 {
class HttpError_1 extends Error {

constructor(status: number, body: {
message: string;
Expand Down
Loading