Closed
Description
This library works great, but I have noticed issues with GET
requests that have no request body on our backend API. The getFetchParams()
always sends the Content-Type
header as application\json
, which throws the following error because the server expects a json body whenever that header is present:
"400 BadRequest: Failed to decode JSON object: Expecting value: line 1 column 1 (char 0)"
We can manually override this by setting Content-Type
to */*
but it would be nice if it would check if there is body data before setting the content type header.
Suggested Fix:
function getFetchParams(request: Request) {
const payload = { ...request.payload } // clone payload
const path = getPath(request.path, payload)
const query = getQuery(request.method, payload, request.queryParams)
- const headers = getHeaders(request.init?.headers)
+ const headers = sendBody(request.method) ? getHeaders(request.init?.headers): new Headers(request.init?.headers)
const url = request.baseUrl + path + query
const init = {
...request.init,
method: request.method.toUpperCase(),
headers,
body: getBody(request.method, payload),
}
return { url, init }
}
Metadata
Metadata
Assignees
Labels
No labels