Skip to content

Commit

Permalink
refactor: create new options object
Browse files Browse the repository at this point in the history
  • Loading branch information
Birkbjo committed Nov 17, 2021
1 parent c7dec65 commit 42f68d7
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/api/Api.js
Original file line number Diff line number Diff line change
Expand Up @@ -211,15 +211,18 @@ class Api {
*/
update(url, data, useMergeStrategy = false, options = {}) {
let payload = data

// Ensure that headers are defined and are treated without case sensitivity
options.headers = new Headers(options.headers || {})
const requestOptions = {
headers: new Headers(options.headers || {})
}

if (data !== undefined) {
if (
!options.headers.has('Content-Type') &&
!requestOptions.headers.has('Content-Type') &&
typeof payload === 'string'
) {
options.headers.set('Content-Type', 'text/plain')
requestOptions.headers.set('Content-Type', 'text/plain')
} else {
payload = JSON.stringify(data)
}
Expand All @@ -234,7 +237,7 @@ class Api {
'PUT',
getUrl(this.baseUrl, urlForUpdate),
payload,
options
requestOptions
)
}

Expand Down

0 comments on commit 42f68d7

Please sign in to comment.