File tree Expand file tree Collapse file tree 2 files changed +29
-11
lines changed
Expand file tree Collapse file tree 2 files changed +29
-11
lines changed Original file line number Diff line number Diff line change @@ -36,14 +36,28 @@ export class ReuniteApiClient implements BaseApiClient {
3636 'user-agent' : `redocly-cli/${ version } ${ this . command } ` ,
3737 } ;
3838
39- const response = await fetchWithTimeout ( url , {
40- ...options ,
41- headers,
42- } ) ;
39+ try {
40+ const response = await fetchWithTimeout ( url , {
41+ ...options ,
42+ headers,
43+ } ) ;
4344
44- this . collectSunsetWarning ( response ) ;
45+ this . collectSunsetWarning ( response ) ;
4546
46- return response ;
47+ return response ;
48+ } catch ( err ) {
49+ let errorMessage = 'Failed to fetch.' ;
50+
51+ if ( err . cause ) {
52+ errorMessage += ` Caused by ${ err . cause . message || err . cause . name } .` ;
53+ }
54+
55+ if ( err . code || err . cause ?. code ) {
56+ errorMessage += ` Code: ${ err . code || err . cause ?. code } ` ;
57+ }
58+
59+ throw new Error ( errorMessage ) ;
60+ }
4761 }
4862
4963 private collectSunsetWarning ( response : Response ) {
Original file line number Diff line number Diff line change 11import { pause } from '@redocly/openapi-core' ;
22import { DeploymentError } from '../utils.js' ;
3+ import { ReuniteApiError } from '../api/index.js' ;
34import { exitWithError } from '../../utils/error.js' ;
45
5- import type { ReuniteApiError } from '../api/index.js' ;
6-
76/**
87 * This function retries an operation until a condition is met or a timeout is exceeded.
98 * If the condition is not met within the timeout, an error is thrown.
@@ -59,8 +58,13 @@ export function handleReuniteError(
5958 message : string ,
6059 error : ReuniteApiError | DeploymentError | Error
6160) {
62- const errorMessage =
63- error instanceof DeploymentError ? error . message : `${ message } Reason: ${ error . message } \n` ;
61+ if ( error instanceof DeploymentError ) {
62+ return exitWithError ( error . message ) ;
63+ }
64+
65+ if ( error instanceof ReuniteApiError ) {
66+ return exitWithError ( `${ message } Reason: ${ error . message } (status: ${ error . status } )\n` ) ;
67+ }
6468
65- return exitWithError ( errorMessage ) ;
69+ return exitWithError ( ` ${ message } Reason: ${ error . message } \n` ) ;
6670}
You can’t perform that action at this time.
0 commit comments