Skip to content

Commit

Permalink
refactor: convert ConnectionError and RequestError to proper classes
Browse files Browse the repository at this point in the history
BREAKING CHANGE: Constructing a `ConnectionError` or `RequestError` now requires to using the `new` keyword.
  • Loading branch information
arthurschreiber authored Oct 8, 2021
1 parent ca8afd3 commit 3e489b4
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 111 deletions.
29 changes: 0 additions & 29 deletions src/errors.d.ts

This file was deleted.

81 changes: 0 additions & 81 deletions src/errors.js

This file was deleted.

28 changes: 28 additions & 0 deletions src/errors.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
export class ConnectionError extends Error {
code: string | undefined;

isTransient: boolean | undefined;

constructor(message: string, code?: string) {
super(message);

this.code = code;
}
}

export class RequestError extends Error {
code: string | undefined;

number: number | undefined;
state: number | undefined;
class: number | undefined;
serverName: string | undefined;
procName: string | undefined;
lineNumber: number | undefined;

constructor(message: string, code?: string) {
super(message);

this.code = code;
}
}
2 changes: 1 addition & 1 deletion test/integration/connection-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1354,7 +1354,7 @@ describe('Advanced Input Test', function() {
const config = getConfig();
config.options.enableAnsiNullDefault = false;

runSqlBatch(done, config, sql, function(/** @type {RequestError | null | undefined} */err) {
runSqlBatch(done, config, sql, function(/** @type {Error | null | undefined} */err) {
assert.instanceOf(err, RequestError);
assert.strictEqual(/** @type {RequestError} */(err).number, 515);
}); // Cannot insert the value NULL
Expand Down

0 comments on commit 3e489b4

Please sign in to comment.