-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make parse fn robust when undefined #24
Comments
And maybe add some test cases for any funny parameters like null, true, false, non-strings etc. |
You can also just check what you're passing in. Not sure what the value would be of being able to pass in something that won't parse anyway without it throwing. What's the use case? |
Passing further the response from any API to your library in the middle of a chain. If the response has no links, is undefined, then I expect the parser to return nothing as well instead of crashing. |
What'd be your expectation of behavior for a malformed link header, for example? Currently that throws. Now, that'd mandate a try/catch around link header parsing anyways, which is why I'm not sure I understand why null / undefined is an issue. |
A simple runtime type validation for the constructor or methods that accept a if (typeof value !== 'string') throw new TypeError('Argument 1 `value` must be a string.'); I ran into a situation where Next.js was mocking Node.js response header related methods, and the header values were always an empty object: Which is a strange behavior, since they should only ever be a string, or array of strings. I had to debug |
We got a similar issue here with: |
When you do something like
LinkHeader.parse(undefined)
it crashes with:I'd make this a bit more robust and would just return undefined as well.
The text was updated successfully, but these errors were encountered: