Skip to content

Commit 75fef30

Browse files
authored
feat: Util v4 (#213)
# Description Updates pollForProcessingImage signature to return an object instead of true/false This allows for the ability to inspect the error in the event its not successful --------- Co-authored-by: Ayan Joshi <[email protected]> Co-authored-by: semantic-release-bot <[email protected]> BREAKING CHANGE: breaks return signature for pollForProcessingImage
1 parent 8d3dcf1 commit 75fef30

File tree

3 files changed

+38
-5
lines changed

3 files changed

+38
-5
lines changed

packages/util/CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
# [@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)
2+
3+
4+
### Features
5+
6+
* 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))
7+
8+
9+
### BREAKING CHANGES
10+
11+
* pollForProcessingImage now returns an object instead of a boolean
12+
113
# [@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)
214

315

packages/util/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@cloudinary-util/util",
3-
"version": "3.3.2",
3+
"version": "4.0.0-beta.1",
44
"type": "module",
55
"main": "./dist/index.cjs",
66
"types": "./dist/index.d.cts",

packages/util/src/lib/cloudinary.ts

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -160,9 +160,15 @@ export interface PollForProcessingImageOptions {
160160
* Poll for an image that hasn't finished processing.
161161
* Will call itself recurisvely until an image is found, or it fails to fetch.
162162
*/
163+
export interface PollForProcessingImageResponse {
164+
status: number;
165+
success: boolean;
166+
error?: string;
167+
}
168+
163169
export async function pollForProcessingImage(
164170
options: PollForProcessingImageOptions,
165-
): Promise<boolean> {
171+
): Promise<PollForProcessingImageResponse> {
166172
try {
167173
const response = await fetch(options.src);
168174

@@ -171,8 +177,23 @@ export async function pollForProcessingImage(
171177
return await pollForProcessingImage(options);
172178
}
173179

174-
return response.ok;
175-
} catch {
176-
return false;
180+
if (!response.ok) {
181+
return {
182+
success: false,
183+
status: response.status,
184+
error: response.headers.get('x-cld-error') || 'Unknown error',
185+
};
186+
}
187+
188+
return {
189+
success: true,
190+
status: response.status,
191+
};
192+
} catch (error) {
193+
return {
194+
success: false,
195+
status: 500,
196+
error: (error as Error).message || 'Network error',
197+
};
177198
}
178199
}

0 commit comments

Comments
 (0)