|
1 | 1 | export default eventHandler(async (event) => { |
2 | | - const data = await readRawBody(event); |
3 | | - const workflowsBucket = useWorkflowsBucket(event); |
| 2 | + try { |
| 3 | + const data = await readRawBody(event); |
| 4 | + const workflowsBucket = useWorkflowsBucket(event); |
4 | 5 |
|
5 | | - const { owner, repo, key } = JSON.parse(data!); |
| 6 | + const { owner, repo, key } = JSON.parse(data!); |
6 | 7 |
|
7 | | - const app = useOctokitApp(event); |
| 8 | + const app = useOctokitApp(event); |
8 | 9 |
|
9 | | - let authenticated = false; |
| 10 | + let authenticated = false; |
10 | 11 |
|
11 | | - try { |
12 | | - await app.octokit.request("GET /repos/{owner}/{repo}/installation", { |
13 | | - owner, |
14 | | - repo, |
15 | | - }); |
16 | | - authenticated = true; |
17 | | - } catch {} |
| 12 | + try { |
| 13 | + await app.octokit.request("GET /repos/{owner}/{repo}/installation", { |
| 14 | + owner, |
| 15 | + repo, |
| 16 | + }); |
| 17 | + authenticated = true; |
| 18 | + } catch {} |
18 | 19 |
|
19 | | - try { |
20 | | - await app.octokit.request("GET /orgs/{org}/installation", { |
21 | | - org: owner, |
22 | | - }); |
23 | | - authenticated = true; |
24 | | - } catch {} |
| 20 | + try { |
| 21 | + await app.octokit.request("GET /orgs/{org}/installation", { |
| 22 | + org: owner, |
| 23 | + }); |
| 24 | + authenticated = true; |
| 25 | + } catch {} |
25 | 26 |
|
26 | | - if (!authenticated) { |
27 | | - throw createError({ |
28 | | - statusCode: 404, |
29 | | - fatal: true, |
30 | | - message: `The app https://github.com/apps/pkg-pr-new is not installed on ${owner}/${repo}.`, |
31 | | - }); |
32 | | - } |
| 27 | + if (!authenticated) { |
| 28 | + throw createError({ |
| 29 | + statusCode: 404, |
| 30 | + fatal: true, |
| 31 | + message: `The app https://github.com/apps/pkg-pr-new is not installed on ${owner}/${repo}.`, |
| 32 | + }); |
| 33 | + } |
| 34 | + |
| 35 | + const workflowData = await workflowsBucket.getItem(key); |
| 36 | + |
| 37 | + if (!workflowData) { |
| 38 | + throw createError({ |
| 39 | + statusCode: 404, |
| 40 | + fatal: true, |
| 41 | + message: `There is no workflow defined for ${key}`, |
| 42 | + }); |
| 43 | + } |
| 44 | + return { sha: workflowData.sha }; |
| 45 | + } catch (error: unknown) { |
| 46 | + console.error("Check route error:", error); |
| 47 | + |
| 48 | + if (error && typeof error === "object" && "statusCode" in error) { |
| 49 | + throw error; |
| 50 | + } |
33 | 51 |
|
34 | | - const workflowData = await workflowsBucket.getItem(key); |
| 52 | + const message = |
| 53 | + error instanceof Error |
| 54 | + ? error.message |
| 55 | + : "An unexpected error occurred during check"; |
| 56 | + const stack = error instanceof Error ? error.stack : undefined; |
35 | 57 |
|
36 | | - if (!workflowData) { |
37 | 58 | throw createError({ |
38 | | - statusCode: 404, |
39 | | - fatal: true, |
40 | | - message: `There is no workflow defined for ${key}`, |
| 59 | + statusCode: 500, |
| 60 | + statusMessage: "Internal Server Error", |
| 61 | + data: { |
| 62 | + error: true, |
| 63 | + message, |
| 64 | + stack, |
| 65 | + originalError: error, |
| 66 | + type: "check_error", |
| 67 | + }, |
41 | 68 | }); |
42 | 69 | } |
43 | | - return { sha: workflowData.sha }; |
44 | 70 | }); |
0 commit comments