Skip to content

Commit 46e46a3

Browse files
authored
🤖 Merge PR DefinitelyTyped#74793 [mssql] Use enum for MSSQLError error codes by @erehulka
1 parent b4043de commit 46e46a3

File tree

2 files changed

+30
-7
lines changed

2 files changed

+30
-7
lines changed

‎types/mssql/index.d.ts‎

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,9 +216,32 @@ export interface config {
216216
beforeConnect?: ((conn: Connection) => void) | undefined;
217217
}
218218

219+
export declare enum MSSQL_ERROR_CODE {
220+
ELOGIN = "ELOGIN",
221+
ETIMEOUT = "ETIMEOUT",
222+
EDRIVER = "EDRIVER",
223+
EALREADYCONNECTED = "EALREADYCONNECTED",
224+
EALREADYCONNECTING = "EALREADYCONNECTING",
225+
ENOTOPEN = "ENOTOPEN",
226+
EINSTLOOKUP = "EINSTLOOKUP",
227+
ESOCKET = "ESOCKET",
228+
ECONNCLOSED = "ECONNCLOSED",
229+
ENOTBEGUN = "ENOTBEGUN",
230+
EALREADYBEGUN = "EALREADYBEGUN",
231+
EREQINPROG = "EREQINPROG",
232+
EABORT = "EABORT",
233+
EREQUEST = "EREQUEST",
234+
ECANCEL = "ECANCEL",
235+
EARGS = "EARGS",
236+
EINJECT = "EINJECT",
237+
ENOCONN = "ENOCONN",
238+
EALREADYPREPARED = "EALREADYPREPARED",
239+
ENOTPREPARED = "ENOTPREPARED",
240+
}
241+
219242
export declare class MSSQLError extends Error {
220-
constructor(message: Error | string, code?: string);
221-
public code: string;
243+
constructor(message: Error | string, code?: MSSQL_ERROR_CODE);
244+
public code: MSSQL_ERROR_CODE;
222245
public name: string;
223246
public originalError?: Error | undefined;
224247
}

‎types/mssql/mssql-tests.ts‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -320,11 +320,11 @@ function test_mssql_errors() {
320320
// Test constructors
321321
const sqlDriverError = new Error("mock error");
322322
const mssqlStringError = new sql.MSSQLError("Something went wrong");
323-
const baseMSSQLError = new sql.MSSQLError(sqlDriverError, "EREQUEST");
324-
const connectionError = new sql.ConnectionError(sqlDriverError, "ELOGIN");
325-
const requestError = new sql.RequestError(sqlDriverError, "EREQUEST");
326-
const preparedStatementError = new sql.PreparedStatementError(sqlDriverError, "EINJECT");
327-
const transactionError = new sql.TransactionError(sqlDriverError, "EABORT");
323+
const baseMSSQLError = new sql.MSSQLError(sqlDriverError, sql.MSSQL_ERROR_CODE.EREQUEST);
324+
const connectionError = new sql.ConnectionError(sqlDriverError, sql.MSSQL_ERROR_CODE.ELOGIN);
325+
const requestError = new sql.RequestError(sqlDriverError, sql.MSSQL_ERROR_CODE.EREQUEST);
326+
const preparedStatementError = new sql.PreparedStatementError(sqlDriverError, sql.MSSQL_ERROR_CODE.EINJECT);
327+
const transactionError = new sql.TransactionError(sqlDriverError, sql.MSSQL_ERROR_CODE.EABORT);
328328

329329
// Test inheritance
330330
if (

0 commit comments

Comments
 (0)