File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -2,7 +2,7 @@ import chalk from "chalk";
22import Table from "cli-table3" ;
33import type { Command } from "commander" ;
44import { loadConfig } from "../helpers/config" ;
5- import { logLoginMessageAndQuit } from "../helpers/errors" ;
5+ import { logAndQuit , logLoginMessageAndQuit } from "../helpers/errors" ;
66import type { Centicents } from "../helpers/units" ;
77import { 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 {
You can’t perform that action at this time.
0 commit comments