WriteErrorCode function always returns 500 code inside JSON payload
Open
Nobody has claimed this yet.
bug
- Dominant language
- Go
- Stars
- 130
- Forks
- 18
- PR merge metrics
- No merged PRs in 30d
Description
Preflight checklist
- I could not find a solution in the existing issues, docs, nor discussions.
- I agree to follow this project's Code of Conduct.
- I have read and am following this repository's Contribution Guidelines.
- I have joined the Ory Community Slack.
- I am signed up to the Ory Security Patch Newsletter.
Describe the bug
I noticed by using the (h *JSONWriter) WriteErrorCode function, that the header is correctly set, but the JSON response returns a 500 status code and message.
Is this a bug or am i interpreting the purpose of the function wrong?
Reproducing the bug
h.d.Writer().WriteErrorCode(w, r, 401, errors.New("error"))
Response:
Version
v0.10.2
On which operating system are you observing this issue?
Linux
In which environment are you deploying?
None
Additional Context
My workaround right now:
h.d.Writer().WriteError(w, r, herodot.DefaultError{
CodeField: 401,
ErrorField: errors.New("error"),
})
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in json.go at the linked WriteErrorCode function and reproduce the behavior with the provided WriteErrorCode call. Verify that the JSON response uses the requested 401 code and error message rather than 500, while preserving the correctly set HTTP header.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 52/100