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
12 changes: 12 additions & 0 deletions packages/util/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
# [@cloudinary-util/util-v4.0.0-beta.1](https://github.com/cloudinary-community/cloudinary-util/compare/@cloudinary-util/util-v3.3.2...@cloudinary-util/util-v4.0.0-beta.1) (2024-10-08)


### Features

* Log X-Cld-Error header in dev mode ([#211](https://github.com/cloudinary-community/cloudinary-util/issues/211)) ([2a5251b](https://github.com/cloudinary-community/cloudinary-util/commit/2a5251b83a44e22d11d4abf9def3bbd975a25f8c))


### BREAKING CHANGES

* pollForProcessingImage now returns an object instead of a boolean

# [@cloudinary-util/util-v3.3.2](https://github.com/cloudinary-community/cloudinary-util/compare/@cloudinary-util/util-v3.3.1...@cloudinary-util/util-v3.3.2) (2024-08-28)


Expand Down
2 changes: 1 addition & 1 deletion packages/util/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@cloudinary-util/util",
"version": "3.3.2",
"version": "4.0.0-beta.1",
"type": "module",
"main": "./dist/index.cjs",
"types": "./dist/index.d.cts",
Expand Down
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',
};
}
}