forwardemail / forwardemail/superagent
Unable to determine if superagent is dismissing the body in response of a request
- Dominant language
- JavaScript
- Stars
- 16.6k
- Forks
- 1.3k
- PR merge metrics
- No merged PRs in 30d
Description
I've just been dealing with an API that set the content type header to `application-json` instead of `application/json` as it should be. This meant that superagent set the res.body to the default of `{}`. This is correct as `application-json` is an incorrect value.
The problem comes when you test the request in the browser (in my case, Chrome v55). The browser doesn't care too much about this slight change in string and parses the body as json. As no error is returned by either superagent or the browser it's difficult to see what the problem is. It took us a day to find the issue and have now changed the API.
I think that superagent should default to an empty object but show a warning of sorts explaining to the user that the body in the superagent response has been defaulted to an empty object as the content-type doesn't match a known string.
Is a warning message something that can be added in for this case or would this not be a valid request?
Contributor guide
Research direction
Reproduce the browser request described in the issue using the malformed `application-json` content type and compare it with `application/json`. Start by tracing superagent's response-body parsing behavior; done means the empty-object fallback remains safe and users receive a warning when the content type is unknown.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- api
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100