johannschopplich / nuxt-api-party

🐬 Securely connect to any API with a server proxy and generated composables
https://nuxt-api-party.byjohann.dev
MIT License
260 stars 10 forks source link

Get status code from `useApiData` #69

Closed m-anwr closed 7 months ago

m-anwr commented 7 months ago

Describe the feature

Currently when I do this:

const { status } = await usApiData("/posts", { ... })
console.log(status.value)

I get "success" as long as no error happened, but I don't get any other values

It would be nice if we could get the status code by doing (for example): status.value.code

Additional information

Final checks

mattmess1221 commented 7 months ago

AsyncData.status is not the HTTP status code of the request, but the activity status of the request. It is one of idle, pending, success, or error. You can get the HTTP status code (albeit not reactively) using the onResponse() callback.

useApiData("endpoint", {
  onResponse(ctx) {
    const status = ctx.response.status
    console.log(`The status was: ${status}`)
  }
}
johannschopplich commented 7 months ago

@killjoy1221 Thanks a lot! I have added a dedicated page to the documentation. It will be live with the next major release.