Skip to content

Commit

Permalink
feat: Log X-Cld-Error header in dev mode (#211)
Browse files Browse the repository at this point in the history
# Description

solving the following issue listed in next-cloudinary 

## Issue Ticket Number

Issue link :
cloudinary-community/next-cloudinary#512

BREAKING CHANGE: pollForProcessingImage now returns an object instead of a boolean
  • Loading branch information
ayan-joshi authored Oct 8, 2024
1 parent a656811 commit 2a5251b
Showing 1 changed file with 25 additions and 4 deletions.
29 changes: 25 additions & 4 deletions packages/util/src/lib/cloudinary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,15 @@ export interface PollForProcessingImageOptions {
* Poll for an image that hasn't finished processing.
* Will call itself recurisvely until an image is found, or it fails to fetch.
*/
export interface PollForProcessingImageResponse {
status: number;
success: boolean;
error?: string;
}

export async function pollForProcessingImage(
options: PollForProcessingImageOptions,
): Promise<boolean> {
): Promise<PollForProcessingImageResponse> {
try {
const response = await fetch(options.src);

Expand All @@ -171,8 +177,23 @@ export async function pollForProcessingImage(
return await pollForProcessingImage(options);
}

return response.ok;
} catch {
return false;
if (!response.ok) {
return {
success: false,
status: response.status,
error: response.headers.get('x-cld-error') || 'Unknown error',
};
}

return {
success: true,
status: response.status,
};
} catch (error) {
return {
success: false,
status: 500,
error: (error as Error).message || 'Network error',
};
}
}

0 comments on commit 2a5251b

Please sign in to comment.