diff --git a/packages/knex/src/error-handler.ts b/packages/knex/src/error-handler.ts index 201d9528eb..97ec4873a6 100644 --- a/packages/knex/src/error-handler.ts +++ b/packages/knex/src/error-handler.ts @@ -65,7 +65,7 @@ export function errorHandler(error: any) { // NOTE: Error codes taken from // https://www.postgresql.org/docs/9.6/static/errcodes-appendix.html // Omit query information - const messages = (error.message || '').split('-') + const messages = error.message.split('-') error.message = messages[messages.length - 1] switch (error.code.slice(0, 2)) { diff --git a/packages/knex/test/error-handler.test.ts b/packages/knex/test/error-handler.test.ts deleted file mode 100644 index 04723a45d1..0000000000 --- a/packages/knex/test/error-handler.test.ts +++ /dev/null @@ -1,65 +0,0 @@ -import assert from 'assert' -import { errorHandler } from '../src' - -describe('Knex Error handler', () => { - it('sqlState', () => { - assert.throws( - () => - errorHandler({ - sqlState: '#23503' - }), - { - name: 'BadRequest' - } - ) - }) - - it('sqliteError', () => { - assert.throws( - () => - errorHandler({ - code: 'SQLITE_ERROR', - errno: 1 - }), - { - name: 'BadRequest' - } - ) - assert.throws(() => errorHandler({ code: 'SQLITE_ERROR', errno: 2 }), { name: 'Unavailable' }) - assert.throws(() => errorHandler({ code: 'SQLITE_ERROR', errno: 3 }), { name: 'Forbidden' }) - assert.throws(() => errorHandler({ code: 'SQLITE_ERROR', errno: 12 }), { name: 'NotFound' }) - assert.throws(() => errorHandler({ code: 'SQLITE_ERROR', errno: 13 }), { name: 'GeneralError' }) - }) - - it('postgresqlError', () => { - assert.throws( - () => - errorHandler({ - code: '22P02', - message: 'Key (id)=(1) is not present in table "users".', - severity: 'ERROR', - routine: 'ExecConstraints' - }), - { - name: 'NotFound' - } - ) - assert.throws( - () => - errorHandler({ code: '2874', message: 'Something', severity: 'ERROR', routine: 'ExecConstraints' }), - { - name: 'Forbidden' - } - ) - assert.throws( - () => - errorHandler({ code: '3D74', message: 'Something', severity: 'ERROR', routine: 'ExecConstraints' }), - { - name: 'Unprocessable' - } - ) - assert.throws(() => errorHandler({ code: 'XYZ', severity: 'ERROR', routine: 'ExecConstraints' }), { - name: 'GeneralError' - }) - }) -})