Skip to content

Commit

Permalink
Handle 401 case for getting orders
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnPhamous committed Jan 4, 2025
1 parent 04dbdb5 commit 2ecf50c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
10 changes: 6 additions & 4 deletions src/helpers/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,18 @@ export function logAndQuit(message: string): never {
process.exit(1);
}

export function logLoginMessageAndQuit(): never {
const base = getCommandBase();
const loginCommand = `${base} login`;
const base = getCommandBase();
const loginCommand = `${base} login`;

export function logLoginMessageAndQuit(): never {
logAndQuit(`You need to login first.\n\n\t$ ${loginCommand}\n`);
}

export async function logSessionTokenExpiredAndQuit(): Promise<never> {
await clearAuthFromConfig();
logAndQuit("\nYour session has expired. Please login again.");
logAndQuit(
`\nYour session has expired. Please login again.\n\n\t$ ${loginCommand}\n`
);
}

export function failedToConnect(): never {
Expand Down
7 changes: 6 additions & 1 deletion src/lib/orders/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,12 @@ export async function getOrders(props: {
});

if (!response.ok) {
logAndQuit(`Failed to fetch orders: ${response.statusText}`);
switch (response.status) {
case 401:
return await logSessionTokenExpiredAndQuit();
default:
return logAndQuit(`Failed to fetch orders: ${response.statusText}`);
}
}

const resp = (await response.json()) as ListResponseBody<HydratedOrder>;
Expand Down

0 comments on commit 2ecf50c

Please sign in to comment.