Skip to content

Commit 4c36fce

Browse files
authored
fix: avoid Object.assign to avoid hiding potential type errors (#1166)
1 parent 98ec3da commit 4c36fce

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

src/types.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,10 @@ export interface State extends Options<any> {
6868
/**
6969
* Error object with optional properties coming from `octokit.request` errors
7070
*/
71-
export type WebhookError = Error & Partial<RequestError>;
71+
export type WebhookError = Error &
72+
Partial<RequestError> & {
73+
event?: EmitterWebhookEventWithStringPayloadAndSignature | undefined;
74+
};
7275

7376
export interface AggregateWebhookError extends AggregateError {
7477
errors: WebhookError[];

src/verify-and-receive.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,12 @@ export async function verifyAndReceive(
2323
if (!matchesSignature) {
2424
const error = new Error(
2525
"[@octokit/webhooks] signature does not match event payload and secret",
26-
);
26+
) as WebhookError;
2727

28-
return state.eventHandler.receive(
29-
Object.assign(error, { event, status: 400 }) as WebhookError,
30-
);
28+
error.event = event;
29+
error.status = 400;
30+
31+
return state.eventHandler.receive(error);
3132
}
3233

3334
let payload: EmitterWebhookEvent["payload"];

0 commit comments

Comments
 (0)