Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle 401 case for getting orders #48

Merged
Show file tree
Hide file tree
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
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
Loading