Skip to content

armgit / spree

Public Imported from GitHub
0

Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.

Fix 202 response body parsing in sdk-core

Damian Legawiec43e4d7533f04
diff --git a/packages/sdk-core/src/request.ts b/packages/sdk-core/src/request.ts
index 8d502cc072..95b41fed4e 100644
--- a/packages/sdk-core/src/request.ts
+++ b/packages/sdk-core/src/request.ts
@@ -193,8 +193,17 @@ export function createRequestFn(
throw new SpreeError(errorBody, response.status);
}
- // Handle 202 Accepted / 204 No Content (empty body)
- if (response.status === 202 || response.status === 204) {
+ // Handle 204 No Content (empty body)
+ if (response.status === 204) {
+ return undefined as T;
+ }
+
+ // Handle 202 Accepted — may or may not have a body
+ if (response.status === 202) {
+ const contentType = response.headers.get('content-type');
+ if (contentType && contentType.includes('application/json')) {
+ return response.json() as Promise<T>;
+ }
return undefined as T;
}