ory / ory/herodot

WriteErrorCode function always returns 500 code inside JSON payload

Open
#128 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Go
Stars
130
Forks
18
PR merge metrics
No merged PRs in 30d

Description

Preflight checklist
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:
Image

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

Open the contributing guide

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 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.