Skip to content

Commit f3876cb

Browse files
committed
fix balance bug
1 parent a287e79 commit f3876cb

1 file changed

Lines changed: 17 additions & 1 deletion

File tree

src/lib/balance.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import chalk from "chalk";
22
import Table from "cli-table3";
33
import type { Command } from "commander";
44
import { loadConfig } from "../helpers/config";
5-
import { logLoginMessageAndQuit } from "../helpers/errors";
5+
import { logAndQuit, logLoginMessageAndQuit } from "../helpers/errors";
66
import type { Centicents } from "../helpers/units";
77
import { getApiUrl } from "../helpers/urls";
88

@@ -88,6 +88,22 @@ async function getBalance(): Promise<{
8888
},
8989
});
9090

91+
if (!response.ok) {
92+
if (response.status === 401) {
93+
logLoginMessageAndQuit();
94+
return {
95+
available: { centicents: 0, whole: 0 },
96+
reserved: { centicents: 0, whole: 0 },
97+
};
98+
}
99+
100+
logAndQuit(`Failed to fetch balance: ${response.statusText}`);
101+
return {
102+
available: { centicents: 0, whole: 0 },
103+
reserved: { centicents: 0, whole: 0 },
104+
};
105+
}
106+
91107
const data = await response.json();
92108

93109
return {

0 commit comments

Comments
 (0)