@@ -28,13 +28,13 @@ function decorateFastifyInstance (pool, fastify, options, next) {
28
28
}
29
29
30
30
if ( fastify . oracle [ options . name ] ) {
31
- return next ( new Error ( 'Connection name has already been registered: ' + options . name ) )
31
+ return next ( Error ( 'fastify-oracle: connection name "' + options . name + '" has already been registered' ) )
32
32
}
33
33
34
34
fastify . oracle [ options . name ] = oracle
35
35
} else {
36
36
if ( fastify . oracle ) {
37
- return next ( new Error ( 'fastify-oracle has already been registered' ) )
37
+ return next ( Error ( 'fastify-oracle has already been registered' ) )
38
38
} else {
39
39
fastify . decorate ( 'oracle' , Object . assign ( oracle , { db : oracledb } ) )
40
40
}
@@ -47,24 +47,30 @@ function decorateFastifyInstance (pool, fastify, options, next) {
47
47
48
48
function fastifyOracleDB ( fastify , options , next ) {
49
49
if ( options . client ) {
50
- if ( oracledb . Pool . prototype . isPrototypeOf ( options . client ) === false ) {
51
- return next ( Error ( 'supplied client must be an instance of oracledb.pool' ) )
50
+ if ( oracledb . Pool . prototype . isPrototypeOf ( options . client ) ) {
51
+ return decorateFastifyInstance ( options . client , fastify , options , next )
52
+ } else {
53
+ return next ( Error ( 'fastify-oracle: supplied client must be an instance of oracledb.pool' ) )
52
54
}
53
- return decorateFastifyInstance ( options . client , fastify , options , next )
54
55
}
55
56
56
57
if ( options . poolAlias ) {
57
- const pool = oracledb . getPool ( options . poolAlias )
58
- if ( ! pool ) return next ( Error ( 'could not get default pool from oracledb instance' ) )
59
- return decorateFastifyInstance ( pool , fastify , options , next )
58
+ try {
59
+ const pool = oracledb . getPool ( options . poolAlias ) // synchronous, throws error
60
+ return decorateFastifyInstance ( pool , fastify , options , next )
61
+ } catch ( err ) {
62
+ return next ( Error ( 'fastify-oracle: could not get pool alias' + '-' + err . message ) )
63
+ }
60
64
}
61
65
62
66
if ( ! options . pool ) {
63
- return next ( Error ( 'must supply options.pool oracledb pool options' ) )
67
+ return next ( Error ( 'fastify-oracle: must supply options.pool oracledb pool options' ) )
64
68
}
65
69
66
70
oracledb . createPool ( options . pool , ( err , pool ) => {
67
- if ( err ) return next ( err )
71
+ if ( err ) {
72
+ return next ( Error ( 'fastify-oracle: failed to create pool' + '-' + err . message ) )
73
+ }
68
74
return decorateFastifyInstance ( pool , fastify , options , next )
69
75
} )
70
76
}
0 commit comments