Skip to content

Commit 4e00e8a

Browse files
author
Idan Levin
committed
Pass errors swallow by promise to the observable
1 parent 14a5488 commit 4e00e8a

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

src/scalecube-services/services/ServiceCall.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
import { Router, Message, utils } from 'src/scalecube-services/services';
44
import { Observable } from 'rxjs/Observable';
5+
// $FlowFixMe
6+
import 'rxjs/add/operator/catch';
7+
58

69
const isObservable = (obj: any): boolean => {
710
if (obj.constructor.name === 'Observable') {
@@ -60,12 +63,14 @@ export class ServiceCall {
6063
observer.error(new Error(`Service not found error: ${message.serviceName}.${message.method}`));
6164
} else if (utils.isLoader(inst)) {
6265
let unsubscribe;
63-
const promise = inst.service.promise;
64-
promise.then((service) => {
65-
unsubscribe = createServiceObserver(message, service, observer);
66+
const promise = new Promise(resolve=>{
67+
inst.service.promise.then((service) => {
68+
resolve(createServiceObserver(message, service, observer));
69+
}).catch(e=>observer.error(e));
70+
6671
});
6772
return () => {
68-
promise.then(() => unsubscribe())
73+
promise.then(unsubscribe => unsubscribe());
6974
};
7075
} else {
7176
return createServiceObserver(message, inst.service, observer);

test/scalecube-services/services/greeting.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ describe('Greeting suite', () => {
3434
.create();
3535

3636
expect.assertions(1);
37-
return expect().rejects.toEqual(new Error("please provide user to greet"));
37+
return expect(greetingService.hello()).rejects.toEqual(new Error("please provide user to greet"));
3838

3939
});
4040
it('Greeting.repeatToStream should return observable of greetings ', () => {
@@ -95,7 +95,7 @@ describe('Greeting suite', () => {
9595
.api(GreetingService)
9696
.create();
9797

98-
expect.assertions(1);
98+
expect.assertions(1);
9999
greetingService.repeatToStream('hey', 'hello').subscribe().unsubscribe();
100100
expect(window['repeatToStreamUnsubscribe']).toBe(true);
101101
});

0 commit comments

Comments
 (0)