File tree Expand file tree Collapse file tree 3 files changed +30
-8
lines changed
Expand file tree Collapse file tree 3 files changed +30
-8
lines changed Original file line number Diff line number Diff line change 99 Application ,
1010 Bundle ,
1111 Content ,
12+ ErrorBody ,
1213 OutputRevision ,
1314 Task ,
1415 User ,
@@ -170,7 +171,19 @@ export class PositCloudClient {
170171 return await response . text ( ) as unknown as T ;
171172 }
172173 } else if ( response . status >= 400 ) {
173- throw new ApiError ( response . status , response . statusText ) ;
174+ const json = await response . json ( ) as unknown as ErrorBody ;
175+ let errorDescription = undefined ;
176+ if ( json . error ) {
177+ errorDescription = json . error ;
178+ if ( json . error_type ) {
179+ errorDescription = `${ errorDescription } , code=${ json . error_type } ` ;
180+ }
181+ }
182+ throw new ApiError (
183+ response . status ,
184+ response . statusText ,
185+ errorDescription ,
186+ ) ;
174187 } else {
175188 throw new Error ( `${ response . status } - ${ response . statusText } ` ) ;
176189 }
Original file line number Diff line number Diff line change @@ -39,3 +39,8 @@ export type Task = {
3939 state : string ;
4040 error ?: string ;
4141} ;
42+
43+ export type ErrorBody = {
44+ error ?: string ;
45+ error_type ?: string ;
46+ } ;
Original file line number Diff line number Diff line change 11/*
2- * types.ts
3- *
4- * Copyright (C) 2020-2022 Posit Software, PBC
5- *
6- */
2+ * types.ts
3+ *
4+ * Copyright (C) 2020-2022 Posit Software, PBC
5+ */
76
87import { ProjectContext } from "../project/types.ts" ;
98
109export class ApiError extends Error {
1110 public constructor (
1211 public readonly status : number ,
13- public readonly statusText : string
12+ public readonly statusText : string ,
13+ public readonly description : string | undefined = undefined ,
1414 ) {
15- super ( `API Error: ${ status } - ${ statusText } ` ) ;
15+ let message = `API Error: ${ status } - ${ statusText } ` ;
16+ if ( description ) {
17+ message = `${ message } (${ description } )` ;
18+ }
19+ super ( message ) ;
1620 }
1721}
1822
You can’t perform that action at this time.
0 commit comments