File tree Expand file tree Collapse file tree 2 files changed +7
-11
lines changed Expand file tree Collapse file tree 2 files changed +7
-11
lines changed Original file line number Diff line number Diff line change @@ -4,11 +4,11 @@ import { FetchError } from '../types'
44
55async function httpResponseErrorHandler ( response : Response ) : Promise < Response > {
66 if ( ! response . ok ) {
7- let err
7+ let responseBody
88 try {
99 // If it is not possible to parse the return body it means there is none
1010 // In which case it is a communication error with the Meilisearch instance
11- err = await response . json ( )
11+ responseBody = await response . json ( )
1212 } catch ( e : any ) {
1313 // Not sure on how to test this part of the code.
1414 throw new MeiliSearchCommunicationError (
@@ -19,8 +19,9 @@ async function httpResponseErrorHandler(response: Response): Promise<Response> {
1919 }
2020 // If the body is parsable, then it means Meilisearch returned a body with
2121 // information on the error.
22- throw new MeiliSearchApiError ( err , response . status )
22+ throw new MeiliSearchApiError ( responseBody , response . status )
2323 }
24+
2425 return response
2526}
2627
Original file line number Diff line number Diff line change @@ -67,14 +67,9 @@ class HttpRequests {
6767 body : JSON . stringify ( body ) ,
6868 headers : this . headers ,
6969 } ) . then ( ( res ) => httpResponseErrorHandler ( res ) )
70- const parsedBody : string = await response . text ( )
71-
72- try {
73- const parsedJson = JSON . parse ( parsedBody )
74- return parsedJson
75- } catch ( _ ) {
76- return
77- }
70+ const parsedBody = await response . json ( ) . catch ( ( ) => null )
71+
72+ return parsedBody
7873 } catch ( e : any ) {
7974 const stack = e . stack
8075 httpErrorHandler ( e , stack , constructURL . toString ( ) )
You can’t perform that action at this time.
0 commit comments