Raw
1 import { CloudStatus } from "types"
2 import { CLOUD_STATUS_PAGE_URL } from "../constants"
3
4 /**
5 * Retrieves the overall status of Medusa Cloud from the public status page.
6 *
7 * The endpoint sets `Access-Control-Allow-Origin: *` and is cached on the
8 * status page's CDN, so it can be fetched directly from the browser.
9 */
10 export async function getCloudStatus(): Promise<CloudStatus> {
11 const response = await fetch(`${CLOUD_STATUS_PAGE_URL}/api/v2/status.json`)
12
13 if (!response.ok) {
14 throw new Error("Failed to fetch the Medusa Cloud status")
15 }
16
17 const data = (await response.json()) as { status?: CloudStatus }
18
19 if (!data.status) {
20 throw new Error("The Medusa Cloud status response has an unexpected format")
21 }
22
23 return data.status
24 }