Skip to content

Commit 4b87fe5

Browse files
committed
fix: catch error
1 parent 301ed70 commit 4b87fe5

File tree

3 files changed

+25
-16
lines changed

3 files changed

+25
-16
lines changed

lib/connection.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,11 @@ class Connection {
1212
return result;
1313
} catch (err) {
1414
this.log.error(err.message);
15-
const error = await this.close();
16-
if (error) {
17-
throw error;
15+
try {
16+
await this.close();
17+
} catch (closeError) {
18+
this.log.error(closeError.message);
19+
throw closeError;
1820
}
1921
throw err;
2022
}

lib/oracle.js

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,14 @@ class OracleDB {
2626
return this.pool.getConnection();
2727
} catch (err) {
2828
this.log.error(err.message);
29-
const error = await this.pool.close();
30-
if (error) {
31-
throw error;
29+
try {
30+
await this.pool.close();
31+
} catch (closeError) {
32+
this.log.error(closeError.message);
33+
this.pool = await oracledb.createPool(this.config);
34+
throw closeError;
3235
}
33-
this.pool = await oracledb.createPool(this.config);
36+
throw err;
3437
}
3538
}
3639
async getConnection() {
@@ -39,11 +42,14 @@ class OracleDB {
3942
return new Connection(connection, this.log);
4043
} catch (err) {
4144
this.log.error(err.message);
42-
const error = await this.pool.close();
43-
if (error) {
44-
throw error;
45+
try {
46+
await this.pool.close();
47+
} catch (closeError) {
48+
this.log.error(closeError.message);
49+
this.pool = await oracledb.createPool(this.config);
50+
throw closeError;
4551
}
46-
this.pool = await oracledb.createPool(this.config);
52+
throw err;
4753
}
4854
}
4955
/**
@@ -63,11 +69,12 @@ class OracleDB {
6369
return result;
6470
} catch (err) {
6571
this.log.error(err.message);
66-
const error = await connection.close();
67-
if (error) {
68-
throw error;
72+
try {
73+
await connection.close();
74+
} catch (error) {
75+
this.log.error(error.message);
76+
this.connection = await this._getConnection();
6977
}
70-
this.connection = await this._getConnection();
7178
throw err;
7279
}
7380
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "egg-oracle",
3-
"version": "1.0.7",
3+
"version": "1.0.9",
44
"description": "Oracle database plugin for egg",
55
"eggPlugin": {
66
"name": "oracle"

0 commit comments

Comments
 (0)