File tree 1 file changed +7
-10
lines changed
1 file changed +7
-10
lines changed Original file line number Diff line number Diff line change 1
1
import type HandlesApiResponse from '../Contracts/HandlesApiResponse' ;
2
2
import type { ApiResponse } from '../Contracts/HandlesApiResponse' ;
3
- import { isObjectLiteral } from '../Support/function' ;
4
3
5
4
/**
6
5
* The default HandlesApiResponse implementation used by upfrontjs.
@@ -24,17 +23,15 @@ export default class ApiResponseHandler implements HandlesApiResponse {
24
23
* @param {ApiResponse } response
25
24
*
26
25
* @return {Promise<any> }
26
+ *
27
+ * @throws {ApiResponse }
27
28
*/
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 ( ) ;
35
32
}
36
33
37
- return responseData ;
34
+ return ;
38
35
}
39
36
40
37
/**
@@ -45,7 +42,7 @@ export default class ApiResponseHandler implements HandlesApiResponse {
45
42
* @return {void }
46
43
*/
47
44
public handleError ( rejectReason : unknown ) : never {
48
- throw new Error ( 'Request has failed with the following message:\n' + String ( rejectReason ) ) ;
45
+ throw rejectReason ;
49
46
}
50
47
51
48
/**
You can’t perform that action at this time.
0 commit comments