Skip to content
This repository was archived by the owner on Sep 2, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions src/error-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,17 @@ export default function errorHandler (error) {
} else if (error instanceof NotFoundError) {
feathersError = new errors.NotFound(message);
} else if (error instanceof UniqueViolationError) {
feathersError = new errors.Conflict(`${error.columns.join(', ')} must be unique`, {
columns: error.columns,
table: error.table,
constraint: error.constraint
});
if (error.client === 'mysql') {
feathersError = new errors.Conflict(error.nativeError.sqlMessage, {
constraint: error.constraint
});
} else {
feathersError = new errors.Conflict(`${error.columns.join(', ')} must be unique`, {
columns: error.columns,
table: error.table,
constraint: error.constraint
});
}
} else if (error instanceof NotNullViolationError) {
feathersError = new errors.BadRequest(`${error.column} must not be null`, {
column: error.column,
Expand Down
12 changes: 12 additions & 0 deletions test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,18 @@ describe('Feathers Objection Service', () => {
expect(errorHandler.bind(null, error)).to.throw(errors.Conflict);
});

it('UniqueViolation error mysql', () => {
const error = new UniqueViolationError({
nativeError: { sqlMessage: 'test' },
client: 'mysql',
table: undefined,
columns: undefined,
constraint: 'test_constraint'
});

expect(errorHandler.bind(null, error)).to.throw(error.Conflict, 'test');
});

it('ConstraintViolation error', () => {
const error = new ConstraintViolationError({
nativeError: new Error(),
Expand Down