Giter VIP home page Giter VIP logo

Comments (5)

leccyril avatar leccyril commented on September 14, 2024

for example i have a call to rest api and then i have to modify the display, using async onRequestError does not work because the display is not modified (cause to the async) so i use a simple try catch but the reponse is not parseable ex

FetchError: 400 (http://localhost:8080/rest/enquiry/create)
at async Proxy.handleSubmit (index.vue:343:5)

i want to retrieve the status and the message error to process the error return properly

from ofetch.

birdlavv avatar birdlavv commented on September 14, 2024

Perhaps you could do something like this:

import { $fetch } from 'ohmyfetch'

const options = {
    // optional auth headers and such
}

const { data, status } = await $fetch.raw('http://httpbin.org/status/404', { ...options })
    .then((response) => ({ data: response._data, status: response.status }))
    .catch((error) => ({ status: error?.response?.status || 502, data: error?.response?._data || undefined }))

from ofetch.

leccyril avatar leccyril commented on September 14, 2024

status is undefined when fetch could not reach the end so i understand why you put the 500 if no status.. ok it is working now...

i think i missed the response between status and error object...

from ofetch.

adarshmadrecha avatar adarshmadrecha commented on September 14, 2024

@leccyril can you close this issue, since your question is answered.

from ofetch.

trandaison avatar trandaison commented on September 14, 2024

If the request could not reach the Server, there are 2 cases:

  • No internet connection.
  • Bad gateway 502.

How to how to determine the case?

from ofetch.

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.