mswjs / data

Data modeling and relation library for testing JavaScript applications.
https://npm.im/@mswjs/data
MIT License
823 stars 52 forks source link

Describe approach of error handling #307

Open vasilii-kovalev opened 2 weeks ago

vasilii-kovalev commented 2 weeks ago

Currently, the documentation doesn't state any approach of how to handle errors.

Topics to cover:

  1. What is the format of errors? Do they have different types (extensions of Error object)? Do they have unique error codes, like Prisma does?
  2. Does a model have built-in validators depending on provided meta-data (like type)? Can users define custom validators? Can they customize errors? If so, can they customize only error messages, or they can return a custom structure? Or should they validate data passed to the model beforehand (using Zod, for example), because the library's scope will be intentionally small?
  3. Is there a difference of handling validation errors (via a dedicated validate method, for example) and other errors? Or are they all handled the same way, like in Prisma?

Even though the library will be rewritten, as mentioned in #285, this information will still be necessary.