Coder Social home page Coder Social logo

Comments (4)

PatrickJS avatar PatrickJS commented on June 14, 2024 1

ok I have it here. but you have to make sure you know how to detect the error from the response object json
#6290

this will only work for any status that fails res.ok and not 500 status

const myFunc = server$(() => {
  if (throwing) {
    throw new ServerError(404, { error: true, data: {} })
  }
  return { error: false, data: {}}
})


const data = await myFunc()
if (data.error) {
  console.log(data.error)
}

this pattern should be way better

const myFunc = server$(() => {
  if (throwing) {
    const errorData = {};
    throw new ServerError(404, [ errorData ])
  }
  const data = {};
  return [null, data]
})


const [err, data] = await myFunc()
if (err) {
  console.log(err)
}

from qwik.

wmertens avatar wmertens commented on June 14, 2024

I like it and prefer option A

from qwik.

DustinJSilk avatar DustinJSilk commented on June 14, 2024

Amazing, thank you @PatrickJS !

from qwik.

PatrickJS avatar PatrickJS commented on June 14, 2024

you have to import from import { ServerError } from "@builder.io/qwik-city/middleware/request-handler"; in the next release

from qwik.

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.