33
44var noop = require ( './util/noop' ) ,
55 extend = require ( 'extend' ) ,
6- querystring = require ( 'querystring' ) ,
6+ qs = require ( 'querystring' ) ,
77 request = require ( 'request' ) ,
88 ArangoError = require ( './error' ) ,
99 Endpoint = require ( './endpoint' ) ,
@@ -29,6 +29,13 @@ Connection.defaults = {
2929} ;
3030
3131extend ( Connection . prototype , {
32+ _resolveUrl : function ( opts ) {
33+ var url = this . config . url ;
34+ if ( ! opts . absolutePath ) url += '/_db/' + this . config . databaseName ;
35+ url += opts . path ? ( opts . path . charAt ( 0 ) === '/' ? '' : '/' ) + opts . path : '' ;
36+ if ( opts . qs ) url += '?' + ( typeof opts . qs === 'string' ? opts . qs : qs . stringify ( opts . qs ) ) ;
37+ return url ;
38+ } ,
3239 endpoint : function ( path ) {
3340 return new Endpoint ( this , path ) ;
3441 } ,
@@ -43,13 +50,8 @@ extend(Connection.prototype, {
4350 headers [ 'content-type' ] = 'application/json' ;
4451 }
4552
46- var url = this . config . url ;
47- if ( ! opts . absolutePath ) url += '/_db/' + this . config . databaseName ;
48- url += opts . path ? ( opts . path . charAt ( 0 ) === '/' ? '' : '/' ) + opts . path : '' ;
49- if ( opts . qs ) url += '?' + ( typeof opts . qs === 'string' ? opts . qs : querystring . stringify ( opts . qs ) ) ;
50-
5153 request ( {
52- url : url ,
54+ url : this . _resolveUrl ( opts ) ,
5355 headers : extend ( headers , this . config . headers , opts . headers ) ,
5456 method : ( opts . method || 'get' ) . toUpperCase ( ) ,
5557 body : body
@@ -61,8 +63,9 @@ extend(Connection.prototype, {
6163 var body = JSON . parse ( rawBody ) ;
6264 if ( ! body . error ) callback ( null , body ) ;
6365 else callback ( new ArangoError ( body ) ) ;
66+ } catch ( e ) {
67+ callback ( e ) ;
6468 }
65- catch ( e ) { callback ( e ) ; }
6669 }
6770 } ) ;
6871 }
0 commit comments