lambdaisland / lambdaisland/fetch

Throws error on :accept :json when response body is empty.

Open
#24 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Clojure
Stars
132
Forks
12
PR merge metrics
No merged PRs in 30d

Description

When you specify an :accept :json header, lambdaisland/fetch will attempt to automatically decode the response body using response.json(). However this will fail and raise an error if the response body is empty (ie JSON.parse('')).
https://github.com/lambdaisland/fetch/blob/246d5615eb242ef092096b6040a1ec011682a924/src/lambdaisland/fetch.cljs#L66-L67

The code should probably check if the body is empty first.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading src/lambdaisland/fetch.cljs at lines 66-67, where :accept :json responses are decoded. Verify the behavior for an empty response body and a nonempty JSON response; done means the empty body no longer raises an error while JSON responses still decode.

Written by the indexing model from the issue text.

Assessment

Tech stack
clojure
Domain
api
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.