cufyorg / moonkit

[ARCHIVED] DSL Based MongoDB driver wrapper for kotlin with an optional schema system
Apache License 2.0
4 stars 2 forks source link

[ORM] A way to customize mongodb exceptions #4

Open LSafer opened 1 year ago

LSafer commented 1 year ago

It is way easier and more performant to depend on the MongoDB to perform the validation (like unique)

But it is not easy to catch those errors and re-throw them with custom messages

I am thinking of an Option to catch those errors and automatically handle them at the proper place using the error's pathname

fun ObjectSchemaBuilder.foo() {
  // idk the actual exception name
   catch<MongoDBUniquenessInvalidationError> { error ->
      if (error.pathname == this.pathname) {
          rethrow(RuntimeError( "foo uniqueness wasn't met" ))
      }
   }
}