/
get-error-handler.ts
37 lines (32 loc) 路 1.15 KB
/
get-error-handler.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import type { Logger } from "pino";
import { WebhookError } from "@octokit/webhooks";
export function getErrorHandler(log: Logger) {
return (error: Error) => {
const errors = (error.name === "AggregateError"
? error
: [error]) as WebhookError[];
for (const error of errors) {
const errMessage = (error.message || "").toLowerCase();
if (errMessage.includes("x-hub-signature")) {
log.error(
error,
"Go to https://github.com/settings/apps/YOUR_APP and verify that the Webhook secret matches the value of the WEBHOOK_SECRET environment variable."
);
continue;
}
if (errMessage.includes("pem") || errMessage.includes("json web token")) {
log.error(
error,
"Your private key (usually a .pem file) is not correct. Go to https://github.com/settings/apps/YOUR_APP and generate a new PEM file. If you're deploying to Now, visit https://probot.github.io/docs/deployment/#now."
);
continue;
}
log
.child({
name: "event",
id: error.event ? error.event.id : undefined,
})
.error(error);
}
};
}