Closed joshua-leyshon-canva closed 3 years ago
Note that I have separately raised the issue of returning an empty link header with Buildkite as well, but I figured we could also improve the default paginate function here 🙂
What does the spec say about empty link? If it's a spec violation, we should at least emit a warning, even if we decide to gracefully handle it.
Good question. This doc is the closest spec I found, which outlines what a link string should look like, but doesn't explicitly say anything about an empty link. Might be up to you how to handle this case 😄
Actually might be empty. The specification defines #link-value
, which means from 0 to infinity occurrences.
Hey @sindresorhus @szmarczak I opened https://github.com/sindresorhus/got/pull/1768 to fix this issue 🦆
Describe the bug
Sometimes (e.g. with Buildkite REST API), a response can contain a link header that is an empty string. The default paginate logic (see just below) doesn't handle this case and will throw when it tries to parse the string. This means we need to add our own paginate logic that is almost identical to the default.
Current default function: https://github.com/sindresorhus/got/blob/06a2d3d7d8d4fcc6898b6364d1a18ca1d407092b/source/core/options.ts#L677
A fix:
Actual behavior
got
throws when parsing an empty string link header.Expected behavior
The default
pagination.paginate
function should returnfalse
when the link header is an empty string.Code to reproduce
Checklist