This is a class of bug I have hit more than once. It is not a story about one private codebase. The HTML is almost never your controller being witty. It is the framework being helpful in the wrong direction.
// problem · 20 may 2026 · 1 min
Laravel authentication error returning HTML instead of JSON
The API client expected JSON. Laravel thought it was talking to a browser.
Time wasted: An embarrassing amount of time
Problem
Environment
Symptoms
Expected
Investigation
Things I tried
Root cause
Solution
Why it worked
Lesson
Found something wrong?
These notes can be incomplete, or wrong in a different environment. Suggest a correction on GitHub or email me at me@t4mer.net.
// related
// til
TIL: Accept and Content-Type are different
Content-Type is what you are sending. Accept is what you are willing to receive. Mixing them is a classic API bug.
// article
Why Postman and Laravel can send “the same request” and get different results
Headers, encodings, and the dangerous comfort of a green Postman screenshot.
// problem
API works in Postman but fails in Laravel
The request you think you are sending is not always the request that leaves the process.