Skip to content

Commit 1e0b58f

Browse files
committed
fix(services)!: removed data unwrapping from ApiResponseHandler
Response may include other keys such as `links`, `meta` and with the previous logic this would have been lost
1 parent 7977360 commit 1e0b58f

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed

src/Services/ApiResponseHandler.ts

+7-10
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import type HandlesApiResponse from '../Contracts/HandlesApiResponse';
22
import type { ApiResponse } from '../Contracts/HandlesApiResponse';
3-
import { isObjectLiteral } from '../Support/function';
43

54
/**
65
* The default HandlesApiResponse implementation used by upfrontjs.
@@ -24,17 +23,15 @@ export default class ApiResponseHandler implements HandlesApiResponse {
2423
* @param {ApiResponse} response
2524
*
2625
* @return {Promise<any>}
26+
*
27+
* @throws {ApiResponse}
2728
*/
28-
public async handleResponse(response: ApiResponse): Promise<any> {
29-
if (!response.json) return;
30-
31-
let responseData = await response.json();
32-
33-
if (isObjectLiteral(responseData) && 'data' in responseData) {
34-
responseData = responseData.data;
29+
public async handleResponse(response: ApiResponse): Promise<unknown | undefined> {
30+
if (typeof response.json === 'function') {
31+
return response.json();
3532
}
3633

37-
return responseData;
34+
return;
3835
}
3936

4037
/**
@@ -45,7 +42,7 @@ export default class ApiResponseHandler implements HandlesApiResponse {
4542
* @return {void}
4643
*/
4744
public handleError(rejectReason: unknown): never {
48-
throw new Error('Request has failed with the following message:\n' + String(rejectReason));
45+
throw rejectReason;
4946
}
5047

5148
/**

0 commit comments

Comments
 (0)