@@ -235,9 +235,15 @@ export class InMemoryBackendService {
235
235
this . setPassThruBackend ( ) ;
236
236
}
237
237
238
-
239
238
createConnection ( req : Request ) : Connection {
240
- const response = this . handleRequest ( req ) ;
239
+ let response : Observable < Response > ;
240
+ try {
241
+ response = this . handleRequest ( req ) ;
242
+ } catch ( error ) {
243
+ const err = error . message || error ;
244
+ const options = createErrorResponse ( STATUS . INTERNAL_SERVER_ERROR , `${ err } ` ) ;
245
+ response = this . createDelayedObservableResponse ( options ) ;
246
+ }
241
247
return {
242
248
readyState : ReadyState . Done ,
243
249
request : req ,
@@ -294,40 +300,32 @@ export class InMemoryBackendService {
294
300
const reqMethodName = RequestMethod [ req . method || 0 ] . toLowerCase ( ) ;
295
301
let resOptions : ResponseOptions ;
296
302
297
- try {
298
- if ( 'commands' === reqInfo . base . toLowerCase ( ) ) {
299
- return this . commands ( reqInfo ) ;
300
-
301
- } else if ( this . inMemDbService [ reqMethodName ] ) {
302
- // If service has an interceptor for an HTTP method, call it
303
- const interceptorArgs : HttpMethodInterceptorArgs = {
304
- requestInfo : reqInfo ,
305
- db : this . db ,
306
- config : this . config ,
307
- passThruBackend : this . passThruBackend
308
- } ;
309
- // The result which must be Observable<Response>
310
- return this . addDelay ( this . inMemDbService [ reqMethodName ] ( interceptorArgs ) ) ;
311
-
312
- } else if ( reqInfo . collection ) {
313
- return this . collectionHandler ( reqInfo ) ;
314
-
315
- } else if ( this . passThruBackend ) {
316
- // Passes request thru to a "real" backend which returns an Observable<Response>
317
- // BAIL OUT with this Observable<Response>
318
- return this . passThruBackend . createConnection ( req ) . response ;
303
+ if ( 'commands' === reqInfo . base . toLowerCase ( ) ) {
304
+ return this . commands ( reqInfo ) ;
319
305
320
- } else {
321
- resOptions = createErrorResponse ( STATUS . NOT_FOUND , `Collection '${ collectionName } ' not found` ) ;
322
- return this . createDelayedObservableResponse ( resOptions ) ;
323
- }
306
+ } else if ( this . inMemDbService [ reqMethodName ] ) {
307
+ // If service has an interceptor for an HTTP method, call it
308
+ const interceptorArgs : HttpMethodInterceptorArgs = {
309
+ requestInfo : reqInfo ,
310
+ db : this . db ,
311
+ config : this . config ,
312
+ passThruBackend : this . passThruBackend
313
+ } ;
314
+ // The result which must be Observable<Response>
315
+ return this . addDelay ( this . inMemDbService [ reqMethodName ] ( interceptorArgs ) ) ;
324
316
325
- } catch ( error ) {
326
- const err = error . message || error ;
327
- resOptions = createErrorResponse ( STATUS . INTERNAL_SERVER_ERROR , `${ err } ` ) ;
317
+ } else if ( reqInfo . collection ) {
318
+ return this . collectionHandler ( reqInfo ) ;
319
+
320
+ } else if ( this . passThruBackend ) {
321
+ // Passes request thru to a "real" backend which returns an Observable<Response>
322
+ // BAIL OUT with this Observable<Response>
323
+ return this . passThruBackend . createConnection ( req ) . response ;
324
+
325
+ } else {
326
+ resOptions = createErrorResponse ( STATUS . NOT_FOUND , `Collection '${ collectionName } ' not found` ) ;
328
327
return this . createDelayedObservableResponse ( resOptions ) ;
329
328
}
330
-
331
329
}
332
330
333
331
/**
0 commit comments