Skip to content

Commit

Permalink
feat(typescript): export WebhookError (#204)
Browse files Browse the repository at this point in the history
  • Loading branch information
gr2m authored Aug 16, 2020
1 parent dfdfc46 commit c3b320b
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/event-handler/receive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { wrapErrorHandler } from "./wrap-error-handler";
import {
WebhookEvent,
State,
OctokitError,
WebhookError,
WebhookEventHandlerError,
} from "../types";
import { EventNames } from "../generated/event-names";
Expand Down Expand Up @@ -60,7 +60,7 @@ export function receiverHandle(state: State, event: WebhookEvent) {
return Promise.resolve();
}

const errors: OctokitError[] = [];
const errors: WebhookError[] = [];
const promises = hooks.map((handler: Function) => {
let promise = Promise.resolve(event);

Expand Down
3 changes: 2 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { middleware } from "./middleware/middleware";
import { sign } from "./sign/index";
import { verify } from "./verify/index";
import { verifyAndReceive } from "./middleware/verify-and-receive";
import { Options, State, WebhookEvent } from "./types";
import { Options, State, WebhookEvent, WebhookError } from "./types";
import { EventNames } from "./generated/event-names";
import { GetWebhookPayloadTypeFromEvent } from "./generated/get-webhook-payload-type-from-event";
import { IncomingMessage, ServerResponse } from "http";
Expand Down Expand Up @@ -71,6 +71,7 @@ export {
createWebhooksApi,
Webhooks,
WebhookEvent,
WebhookError,
sign,
verify,
};
2 changes: 1 addition & 1 deletion src/middleware/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { getPayload } from "./get-payload";
import { verifyAndReceive } from "./verify-and-receive";
import { debug } from "debug";
import { IncomingMessage, ServerResponse } from "http";
import { State, OctokitError, WebhookEventHandlerError } from "../types";
import { State, WebhookError, WebhookEventHandlerError } from "../types";
import { EventNames } from "../generated/event-names";
import AggregateError from "aggregate-error";

Expand Down
6 changes: 3 additions & 3 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,21 @@ export interface State extends Options<any> {
/**
* Error object with optional poperties coming from `octokit.request` errors
*/
export type OctokitError = Error &
export type WebhookError = Error &
Partial<RequestError> & {
/**
* @deprecated `error.event` is deprecated. Use the `.event` property on the aggregated error instance
*/
event: WebhookEvent;
};

export interface WebhookEventHandlerError extends AggregateError<OctokitError> {
export interface WebhookEventHandlerError extends AggregateError<WebhookError> {
event: WebhookEvent;

/**
* @deprecated `error.errors` is deprecated. Use `Array.from(error)`. See https://npm.im/aggregate-error
*/
errors: OctokitError[];
errors: WebhookError[];
}

// temporary using a custom AggregateError type.
Expand Down
7 changes: 7 additions & 0 deletions test/typescript-validate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
EventNames,
EventPayloads,
WebhookEvent,
WebhookError,
} from "../src/index";
import { createServer } from "http";

Expand Down Expand Up @@ -125,3 +126,9 @@ export default async function () {

createServer(webhooks.middleware).listen(3000);
}

export function webhookErrorTest(error: WebhookError) {
const { event, request } = error;
console.log(event);
console.log(request);
}

0 comments on commit c3b320b

Please sign in to comment.