PhilWaldmann / openrecord

Make ORMs great again!
https://openrecord.js.org
MIT License
486 stars 38 forks source link

How can one import/require the ValidationError class? #109

Closed incompletude closed 4 years ago

incompletude commented 4 years ago

I think the best way to give validation error a proper bad request response is to check if error is a instance of ValidationError, but I could not find a way to import the object.

  try {
    const person = await PersonService.create(req.body)

    res.json({
      result: true,
      message: 'Person created.',
      token: person.token
    })
  } catch (error) {
    if (error instanceof ValidationError) { doSomething() return }
    next(error)
    return
  }

I think this info should be in the documentation. Do you mind clarifying me?

I can open a PR to add this and fix a few other errors.

PhilWaldmann commented 4 years ago

Yes, you are right. It's not yet in the documentation. Your store has access to the ValidationError Class via store.ValidationError.