Comments (13)
Okay, I'll make it so if !response.ok
then set an error.
from use-http.
I will try to fix this today.
from use-http.
Yes, you can do for the time being until I get the tests up for this.
const { loading, error, data, response } = useFetch(`${BASE_URL}/${uuid}`, [uuid])
if (!response.ok) {
// the request didn't succeed with a status code < 300
}
Apologies this is taking so long. Juggling a lot of work right now.
Side note, you can set that BASE_URL
in the <Provider url={BASE_URL}><RestOfApp /></Provider>
and do useFetch({ path: `/${uuid}` }, [uuid])
from use-http.
Okay everyone, this should be fixed in v0.2.6
. I'm going to close this, but do comment back on here if something is not working and I'll reopen the issue!
const { error } = useFetch('https://example.com/todos', [])
console.log('Error Name: ', error.name) // ex: 401
console.log('Error Message: ', error.message) // ex: Unauthorized
from use-http.
What is the error to be? What if it's just an error code?
from use-http.
response.status === 404
are we to say
error === 'Not Found'
?
from use-http.
English is not my native language so having to compare strings feels weird to me. I would say error === 404 but I don't know how other libs does that.
Maybe message === Not Found
but allow access to the full response somehow?
from use-http.
Currently, is there any way to handle a 404 apart from implementing "manual" handling?
const { loading, error, data } = useFetch(`${BASE_URL}/${uuid}`, [uuid]);
// the above is a 404 but error is undefined
Thanks
from use-http.
It's implemented and works, but I need to make tests first. You can see the PR here
from use-http.
Currently, is there any way to handle a 404 apart from implementing "manual" handling?
const { loading, error, data } = useFetch(`${BASE_URL}/${uuid}`, [uuid]); // the above is a 404 but error is undefined
I used version 0.2.5 and when server returns 404, I get the error:
error: TypeError: Failed to execute 'text' on 'Response': body stream is locked at _callee
from use-http.
I used version 0.2.5 and when server returns 404, I get the error:
error: TypeError: Failed to execute 'text' on 'Response': body stream is locked at _callee
This error was due to fact that my server returned text error message, not json. When the response with status 404 contains json in its body, error is undefined.
from use-http.
@alex-cory Don't stress out over it, take your time :) We all have work and personal lives to take care of! Thanks
from use-http.
Hi, @alex-cory , I still don't know how to get error when promise resolved,
const { get, response, error } = useFetch("/xxxx")
useEffect(() => {
const init = async () => {
await get()
if(!response.ok){
// how to get error here?
console.log('error ',error );
}
}
init()
}, [])
from use-http.
Related Issues (20)
- [Question] How to change the interceptor's request route value? HOT 1
- function to overwrite global options don't update after dependency change HOT 6
- useFetch `post` call inserts quotes when passed a string HOT 6
- React Native and Cache
- [Feature Request] time denounce http get requests
- does useFetch have option for skip request?
- Data not populated at mount HOT 5
- React 18 StrictMode HOT 22
- `Error: Invalid hook call` after upgrading to React 18.1 HOT 1
- Interceptors aren't chained HOT 8
- Cannot abort delayed retries
- use-Fetch Post is having issue with csrf headers HOT 7
- [Feature Request] A way to invalidate the cache HOT 1
- Upload File Progress
- can recall post when parameter change?
- does post can auto fire? HOT 2
- Eslint rule react-hooks/exhaustive-deps questions on having response as depency HOT 1
- React 18 not supported? HOT 1
- Following instructions in .github/contributing.md fails when using the latest React 18 HOT 2
- Initial URL with a trailing slash adds double slash on relative urls
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 use-http.