Skip to content

Commit b111714

Browse files
chore: show more push command error details (#2415)
1 parent bc7ebb1 commit b111714

File tree

2 files changed

+29
-11
lines changed

2 files changed

+29
-11
lines changed

packages/cli/src/reunite/api/api-client.ts

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff 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) {

packages/cli/src/reunite/commands/utils.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
import { pause } from '@redocly/openapi-core';
22
import { DeploymentError } from '../utils.js';
3+
import { ReuniteApiError } from '../api/index.js';
34
import { 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
}

0 commit comments

Comments
 (0)