Skip to content

onError not working in Objection 2 #1731

@PatrickLef

Description

@PatrickLef

Thank you for all your good work on Objection!

After upgrading to Objection 2 the .onError() method has stopped working as intended.

When running this

const person = await Person.query()
  .insert({
    lastName: '', // this causes a validation error
  })
  .onError((e) => {
    return 'error'
  })

I expect
person === 'error'
Instead i get
person === undefined

Please see the following gist to reproduce this.

https://gist.github.com/PatrickLef/ce162c2533211ac2102ca7748f606d56

Running it with version 1 of objection
package.json

{
  "dependencies": {
    "chai": "4.2.0",
    "knex": "0.20.13",
    "objection": "1.6.11",
    "sqlite3": "4.1.1"
  }
}

Produces a success and we can see that the insert with on error successfully returns 'error'

image

Running it with version 2 of objection
package.json

{
  "dependencies": {
    "chai": "4.2.0",
    "knex": "0.20.13",
    "objection": "2.1.3",
    "sqlite3": "4.1.1"
  }
}

Produces an error for the expect and we can see the query did not return expected 'error' but instead returns undefined

image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions