Skip to content

Commit 1c57026

Browse files
committed
Extract HTTP status for reuse
1 parent 7723020 commit 1c57026

File tree

3 files changed

+9
-6
lines changed

3 files changed

+9
-6
lines changed

src/netlify/http.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export const enum Status {
2+
OK = 200,
3+
BAD_REQUEST = 400,
4+
}

src/netlify/repo_event.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,7 @@ import { SIGNATURE_HEADER, validatePayload } from "../github.js";
44
import { notifyChannel } from "../slack.js";
55
import type { Maybe, Repository } from "../types.js";
66

7-
const enum HttpStatus {
8-
OK = 200,
9-
BAD_REQUEST = 400,
10-
}
7+
import { Status as HttpStatus } from "./http.js";
118

129
type Event = Pick<HandlerEvent, "body" | "headers">;
1310

src/netlify/slack_interaction.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import { deleteRepo } from "../github.js";
44
import { SIGNATURE_HEADER, TIMESTAMP_HEADER, updateMessage, validatePayload } from "../slack.js";
55
import type { Maybe, MessageRef } from "../types.js";
66

7+
import { Status as HttpStatus } from "./http.js";
8+
79
type Event = Pick<HandlerEvent, "body" | "headers">;
810

911
const handler = (async (event: Event): Promise<HandlerResponse> => {
@@ -12,7 +14,7 @@ const handler = (async (event: Event): Promise<HandlerResponse> => {
1214
payload = validatePayload(getBody(event), getSignature(event), getTimestamp(event));
1315
} catch (err) {
1416
console.error(err);
15-
return { statusCode: 400 };
17+
return { statusCode: HttpStatus.BAD_REQUEST };
1618
}
1719
if (payload) {
1820
try {
@@ -24,7 +26,7 @@ const handler = (async (event: Event): Promise<HandlerResponse> => {
2426
console.error(err);
2527
}
2628
}
27-
return { statusCode: 200 };
29+
return { statusCode: HttpStatus.OK };
2830
}) satisfies Handler;
2931

3032
const getBody = ({ body }: Event): string => {

0 commit comments

Comments
 (0)