Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rework implementation with initial .cause support #304

Open
wants to merge 23 commits into
base: next
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 6 additions & 6 deletions lib/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export interface Options<Data> {
/**
* An object containing any HTTP headers where each key is a header name and value is the header content
*/
readonly headers?: { [header: string]: string | string[] | number };
readonly headers?: { [header: string]: string | readonly string[] | number };
kanongil marked this conversation as resolved.
Show resolved Hide resolved

/**
* Constructor reference used to crop the exception call stack output
Expand Down Expand Up @@ -116,17 +116,17 @@ export interface Output {
/**
* The HTTP status code
*/
readonly statusCode: number;
statusCode: number;

/**
* An object containing any HTTP headers where each key is a header name and value is the header content
*/
readonly headers: { [header: string]: string | string[] | number | undefined };
headers: { [header: string]: string | string[] | number | undefined };

/**
* The formatted object used as the response payload (stringified)
*/
readonly payload: Payload;
payload: Payload & { [key: string]: unknown };
}


Expand Down Expand Up @@ -213,7 +213,7 @@ export namespace unauthorized {
*
* @returns A 401 Unauthorized error
*/
export function unauthorized(message: string | null | undefined, wwwAuthenticate: string[]): Boom<null>;
export function unauthorized(message: string | null | undefined, wwwAuthenticate: readonly string[]): Boom<null>;


/**
Expand Down Expand Up @@ -258,7 +258,7 @@ export function notFound<Data>(message?: string, data?: Data): Boom<Data>;
*
* @returns A 405 Method Not Allowed error
*/
export function methodNotAllowed<Data>(message?: string, data?: Data, allow?: string | string[]): Boom<Data>;
export function methodNotAllowed<Data>(message?: string, data?: Data, allow?: string | readonly string[]): Boom<Data>;


/**
Expand Down
5 changes: 5 additions & 0 deletions test/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ expect.type<Boom.Boom>(new CustomError('Some error'));

const boom = new Boom.Boom('some error');
expect.type<Boom.Output>(boom.output);
boom.output.payload.custom_null = null;
boom.output.payload.custom_number = 42;
boom.output.payload.custom_string = 'foo';
boom.output.payload.custom_boolean = true;
boom.output.payload.custom_object = { bar: 42 };
boom.output.headers['header1'] = 'foo';
boom.output.headers['header2'] = ['foo', 'bar'];
boom.output.headers['header3'] = 42;
Expand Down