Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 20 additions & 6 deletions packages/cli/src/reunite/api/api-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,28 @@ export class ReuniteApiClient implements BaseApiClient {
'user-agent': `redocly-cli/${version} ${this.command}`,
};

const response = await fetchWithTimeout(url, {
...options,
headers,
});
try {
const response = await fetchWithTimeout(url, {
...options,
headers,
});

this.collectSunsetWarning(response);
this.collectSunsetWarning(response);

return response;
return response;
} catch (err) {
let errorMessage = 'Failed to fetch.';

if (err.cause) {
errorMessage += ` Caused by ${err.cause.message || err.cause.name}.`;
}

if (err.code || err.cause?.code) {
errorMessage += ` Code: ${err.code || err.cause?.code}`;
}

throw new Error(errorMessage);
}
}

private collectSunsetWarning(response: Response) {
Expand Down
14 changes: 9 additions & 5 deletions packages/cli/src/reunite/commands/utils.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { pause } from '@redocly/openapi-core';
import { DeploymentError } from '../utils.js';
import { ReuniteApiError } from '../api/index.js';
import { exitWithError } from '../../utils/error.js';

import type { ReuniteApiError } from '../api/index.js';

/**
* This function retries an operation until a condition is met or a timeout is exceeded.
* If the condition is not met within the timeout, an error is thrown.
Expand Down Expand Up @@ -59,8 +58,13 @@ export function handleReuniteError(
message: string,
error: ReuniteApiError | DeploymentError | Error
) {
const errorMessage =
error instanceof DeploymentError ? error.message : `${message} Reason: ${error.message}\n`;
if (error instanceof DeploymentError) {
return exitWithError(error.message);
}

if (error instanceof ReuniteApiError) {
return exitWithError(`${message} Reason: ${error.message} (status: ${error.status})\n`);
}

return exitWithError(errorMessage);
return exitWithError(`${message} Reason: ${error.message}\n`);
}
Loading