Openstatus
www.openstatus.dev
1import { regions } from "../regions/fly";
2import type { ParserReturn, Region } from "../types";
3
4export function parseFlyRequestId(header: string): ParserReturn<Region> {
5 const regex = /\b([a-z]{3})\b/g;
6 const arr = header.match(regex);
7
8 if (!arr || arr.length === 0) {
9 return { status: "failed", error: new Error("Couldn't parse the header.") };
10 }
11
12 const region = regions[arr[0]];
13 if (region) return { status: "success", data: region };
14
15 return {
16 status: "failed",
17 error: new Error(
18 `It seems like the data center '${arr[0]}' (iata) is not listed.`,
19 ),
20 };
21}