Comments (4)
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
from fetch.
999 is not allowed according to the fetch specification, can you try using the native fetch function and see what happens please?
from fetch.
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.
from fetch.
Any updates here? @JakeChampion
from fetch.
Related Issues (20)
- 📢 🎉 We’ve made some exciting improvements to our [REST API documentation](https://docs.github.com/en/rest) and we'd love to know what you think about the new layout! Let us know 👇 HOT 1
- Thanks for opening this pull request! A GitHub docs team member should be by to give feedback soon. In the meantime, please check out the [contributing guidelines](https://github.com/github/docs/blob/main/CONTRIBUTING.md). HOT 1
- This repository is moving from the github org HOT 2
- Owner [email protected]
- 2018 license appachie com [email protected]
- Refused to get unsafe header "set-cookie"
- Owner
- changelog is missing for latest releases HOT 1
- File fetching broken since commit 0c1d2b9 HOT 3
- Create a Security Policy HOT 1
- Enable OpenSSF Scorecard Action HOT 3
- `Set-Cookie` headers should not be combined / Support `Headers.getSetCookie()` method
- Hash pin actions used on workflows and enable depenadabot
- code is working in chrome, not in firefox HOT 2
- Overriding feature detection HOT 2
- suggestion to use str.indexOf(searchString) === 0 for better compatibility HOT 2
- UMD Releases don't exist HOT 1
- Response does not resolve until body fetched
- Response.body is always undefined HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fetch.