-
Notifications
You must be signed in to change notification settings - Fork 122
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(orm): better Error handling + UniqueConstraintFailure
With this commit all errors public ORM end points (query patch, query delete, session insert, session update, session remove) are caught and normalized to either DatabaseError or to one of its subclasses. All errors now contain `cause` to be able to get the original error in the error chain. This way no information is lost. UniqueConstraintFailure now contains the full error message from the underlying database driver to get more information about it. Adjusted: DatabasePatchError: - [x] MySQL: query patch - [x] SQLite: query patch - [x] Postgres: query patch - [x] Mongo: query patch DatabaseDeleteError: - [x] MySQL: query delete, session remove - [x] SQLite: query delete, session remove - [x] Postgres: query delete, session remove - [x] Mongo: query delete, session remove DatabaseUpdateError: - [x] MySQL: session update - [x] SQLite: session update - [x] Postgres: session update - [x] Mongo: session update DatabaseInsertError: - [x] MySQL: session insert - [x] SQLite: session insert - [x] Postgres: session insert - [x] Mongo: session insert UniqueConstraintFailure: - [x] MySQL: session insert, query patch, session update - [x] SQLite: session insert, query patch, session update - [x] Postgres: session insert, query patch, session update - [x] Mongo: session insert, query patch, session update
- Loading branch information
Showing
28 changed files
with
716 additions
and
149 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { DatabaseError, DatabaseSession, UniqueConstraintFailure } from '@deepkit/orm'; | ||
|
||
/** | ||
* Converts a specific database error to a more specific error, if possible. | ||
*/ | ||
export function handleSpecificError(session: DatabaseSession, error: DatabaseError): Error { | ||
let cause: any = error; | ||
while (cause) { | ||
if (cause instanceof Error) { | ||
if (cause.message.includes('duplicate key error') | ||
) { | ||
return new UniqueConstraintFailure(`${cause.message}`, { cause: error }); | ||
} | ||
cause = cause.cause; | ||
} | ||
} | ||
|
||
return error; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.