got: Got throws an HTTPError for 304 responses

Currently implementing an API client that supports caching. It sends if-modified-since headers and will sometimes get a 304 response. If I get a 304, got throws an HTTPError. I can’t catch the error and then do my stuff because the error doesn’t contain the headers.

I noticed this in the readme:

got.HTTPError

When server response code is not 2xx. Contains statusCode and statusMessage.

Why isn’t 304 allowed?

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Comments: 24 (24 by maintainers)

Most upvoted comments

@lukechilds It’s just my opinion, but if got does not behave differently (rejects) in case of 304, it force users to handle this case or they will find themselves without any content.

I know that it should only happen when the correct headers are set but still, I think it’s much more obvious to debug when an error is thrown.

@lukechilds response property is hidden from console.log (because it is huge and spamming logs is bad). Try:

.catch((err) => console.log(err.response))