Two bugs turned up in two completely different projects, one in a desktop app's GitHub integration and one in a small analytics dashboard, and they turned out to be the same bug wearing different clothes. Both were APIs where the response for "it worked" and the response for "it didn't, here's why" were close enough in structure that the code kept walking down the happy path without anything telling it otherwise.

The device flow that answers 200 either way

I've been adding a second GitHub account to Chief, a desktop app that ties into a user's own accounts, through GitHub's device authorization flow: the one where you get a short code and enter it on a separate page. The account doing the testing was newly registered, and GitHub disables device flow by default for every new OAuth app.

GitHub answers "this isn't available" with an HTTP 200 and an error field sitting in the body: the same status code and nearly the same structure you'd get from a real success response. Code that treats 200 as "read the payload as a success" has no reason to look twice.

That's what happened here. The client tried to read fields that only exist on the happy path, found nothing usable, and reported the whole thing as a JSON parsing failure. A user filing a bug for that would write something like "linking my account doesn't work", which is true and tells nobody anything.

It isn't unique to the disabled-app case either. The polling step of device flow routinely returns error codes for perfectly normal states: authorization_pending while nobody has approved yet, slow_down if you're polling too fast. All of it arrives as HTTP 200. A client built only around the success case is exposed the moment it meets any of those, and "device flow disabled" was simply the one that showed up first.

The fix was to check the error field before reading anything else, and to give the specific case a name: device_flow_disabled, not "couldn't parse the response." Naming it matters because it's the default state of every fresh OAuth app, which makes it the very first thing anyone testing a new install is going to hit.

The token that was there, one level down

The second bug lived in a small dashboard I built to show visitor and page-view counts for this site, using Ghost's own analytics. Ghost's numbers are backed by Tinybird, but a managed Ghost host doesn't hand you a Tinybird workspace token directly. You get one through Ghost's Admin API instead, which proxies the request and passes back whatever Tinybird gave it.

In production, that response arrived wrapped: an object with the token and its expiry nested one level down, inside a tinybird key. The code expected the token as a bare value. It didn't crash or log anything; it just read undefined, treated that as "no analytics available right now", and moved on. The footer status dot that was supposed to show sync health just stayed grey.

Same root cause as the device-flow bug, one layer over: a structure the code assumed the API would keep matching, and it stopped. The fix was to prefer the wrapped shape, fall back to a bare one for safety, and let a response that really has no token fail somewhere visible instead of folding into the same branch as "the token is nested a level down."

The same mistake, two layers apart

Neither of these is a hard bug once you've seen it, and that's why they survive review: the code reads perfectly reasonably if you don't already know the API can hand you a response you hadn't planned for. I've written before about bugs that do exactly what the code says, and these fit the pattern: nothing broke in the sense of throwing an exception, the values were only wrong to someone who knew what right looked like.

What fixed both was checking the one field that tells the cases apart before trusting anything else in the payload:

if (response.error) {
  handle(response.error) // named, not generic
} else if (response.tinybird?.token) {
  use(response.tinybird.token)
} else if (response.token) {
  use(response.token)
} else {
  fail('no usable token in response')
}

A generic catch, a swallowed parse error or an undefined value treated as empty all tell you nothing about which of several different situations you're actually in, and each one deserves a name if you want the next debugging session to take minutes instead of an afternoon.

Both were third-party APIs, so I controlled neither their versioning nor their idea of what a success response looks like. In both cases the check was a few lines, and skipping it cost me an afternoon each time before the pattern was obvious enough to write down.