Skip to content
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

Linkedin uses status code 999 which leads to RangeError #1415

Open
martinsunnyclock opened this issue Dec 12, 2023 · 4 comments
Open

Linkedin uses status code 999 which leads to RangeError #1415

martinsunnyclock opened this issue Dec 12, 2023 · 4 comments

Comments

@martinsunnyclock
Copy link

martinsunnyclock commented Dec 12, 2023

LinkedIn uses status code 999 and thus it triggers a RangeError when calling a linkedin url.

For example you can call: https://www.linkedin.com/in/someone

I think therefore 999 should be included in the status code range check although it's unofficial.

@martinsunnyclock martinsunnyclock changed the title Linkedin uses status code 999 Linkedin uses status code 999 which leads to RangeError Dec 12, 2023
@JakeChampion
Copy link
Owner

999 is not allowed according to the fetch specification, can you try using the native fetch function and see what happens please?

@martinsunnyclock
Copy link
Author

Thanks a lot for the fast reply.

I did what you suggested by using a local express server.

const express = require('express')
const app = express()
const port = 3000

app.get('/', (req, res) => {
  res.status(999).send('Hello World!')
})

app.listen(port, () => {
  console.log(`Example app listening on port ${port}`)
})

Then in the browser:

const ninenineninefetch = async () => {
    try {
        const response = await fetch('http://localhost:3000')
        const text = await response.text();
        console.log(response.status, text)
    } catch(e) {
        console.log('error', e)
    }
}
ninenineninefetch();

Which will output 999 'Hello World!' without triggering the catch.
Tried on Firefox and Chrome.

I also found this:
https://fetch.spec.whatwg.org/#statuses

Which states a status is in the range from 0 to 999.

@JakeChampion
Copy link
Owner

Thanks for the above code.

If you construct a Response in JS directly and not via fetch it will error:

new Response('',{status:999})
// Uncaught RangeError: Response constructor: Invalid response status code.
//    <anonymous> debugger eval code:1

It looks to me like the host environment can accept wider range statuses than can be constructed with the Response class, this will take a bit of code juggling to solve.

To initialize a response, given a Response object response, ResponseInit init, and null or a body with type body:

If init["status"] is not in the range 200 to 599, inclusive, then throw a RangeError.

Source: https://fetch.spec.whatwg.org/#initialize-a-response

@SlyryD
Copy link

SlyryD commented Mar 4, 2024

Any updates here? @JakeChampion

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants