Giter VIP home page Giter VIP logo

Comments (13)

alex-cory avatar alex-cory commented on May 14, 2024 1

Okay, I'll make it so if !response.ok then set an error.

from use-http.

alex-cory avatar alex-cory commented on May 14, 2024 1

I will try to fix this today.

from use-http.

alex-cory avatar alex-cory commented on May 14, 2024 1

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.

alex-cory avatar alex-cory commented on May 14, 2024 1

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.

alex-cory avatar alex-cory commented on May 14, 2024

What is the error to be? What if it's just an error code?

from use-http.

alex-cory avatar alex-cory commented on May 14, 2024

response.status === 404
are we to say
error === 'Not Found'?

from use-http.

niicojs avatar niicojs commented on May 14, 2024

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.

denizdogan avatar denizdogan commented on May 14, 2024

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.

alex-cory avatar alex-cory commented on May 14, 2024

It's implemented and works, but I need to make tests first. You can see the PR here

from use-http.

Zdenek-M avatar Zdenek-M commented on May 14, 2024

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.

Zdenek-M avatar Zdenek-M commented on May 14, 2024

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.

denizdogan avatar denizdogan commented on May 14, 2024

@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.

theowenyoung avatar theowenyoung commented on May 14, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.