Skip to content
This repository was archived by the owner on Aug 21, 2025. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions src/util/graphql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import { Org, Project } from "../util/types.js";
import { getSlugFromName } from "./index.js";
import chalk from "chalk";

export async function sendGraphQLReqToHypermode(jwt: string, query: string): Promise<any> {
const url = "https://api.hypermode.com/graphql";
Expand All @@ -22,10 +23,23 @@ export async function sendGraphQLReqToHypermode(jwt: string, query: string): Pro
method: "POST",
};

const response = await fetch(url, options);
try {
const response = await fetch(url, options);

const data: any = await response.json();
return data;
if (!response.ok) {
if (response.status === 401) {
console.error(`Unauthorized. Please try ${chalk.blueBright("hyp login")} again.`);
throw new Error("Unauthorized: Invalid or expired JWT token.");
} else {
throw new Error(`HTTP Error: ${response.status} ${response.statusText}`);
}
}

const data = await response.json();
return data;
} catch (error: any) {
throw new Error(`Failed to send GraphQL request: ${error?.message}`);
}
}

export async function sendMapRepoAndFinishProjectCreationReq(jwt: string, id: string, repoId: string, repoName: string): Promise<Project> {
Expand Down
Loading