Skip to content

Error Handling from docs completely not working #2688

@KrisLau

Description

@KrisLau

Doc: https://vincit.github.io/objection.js/recipes/error-handling.html#examples

Error I'm testing:

 RequestError: insert into [user] (//columns) output inserted.[id] values (@p0, @p1, @p2, @p3, @p4, @p5, @p6, @p7, @p8, @p9, @p10) - Violation of PRIMARY KEY constraint 'user_pkey'. Cannot insert duplicate key in object 'dbo.user'. The duplicate key value is (//id).
 User.query(trx)
  .insert(created)
  .onError(async (error, _query) => {
    const testErr = errorHandler(error);

    console.log(testErr.type); //always returns UnknownError
    console.log(error.type); //always returns undefined

    // returns false for all
    console.log(error instanceof CheckViolationError);
    console.log(error instanceof ForeignKeyViolationError);
    console.log(error instanceof ConstraintViolationError);
    
    // other code

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