Skip to content

Commit

Permalink
Fix issues 406 errors
Browse files Browse the repository at this point in the history
We set content-type null on UJS as a flag to remove it later down
the stack. I'm not sure why I did it this way, but it missed a case
when the method type on the form was a GET. This resulted in
content-type of "null" being sent to the server.

This isn't the best fix and I have to find a better way of achieving
the same thing.
  • Loading branch information
jho406 committed Jun 4, 2024
1 parent 318b66d commit 091c076
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions superglue/lib/utils/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,17 @@ export function argsForFetch(
'x-superglue-request': true,
}

// This needs to be done better. This is saying to
// remove the content-type header from UJS form
// submissions.
const fromUJSForm = headers['content-type'] === null

if (method != 'GET' && method != 'HEAD') {
if (headers['content-type'] === null) {
delete headers['content-type']
} else {
headers['content-type'] = 'application/json'
}
headers['content-type'] = 'application/json'
}

if (fromUJSForm) {
delete headers['content-type']
}

if (currentState.csrfToken) {
Expand Down

0 comments on commit 091c076

Please sign in to comment.