Skip to content
This repository has been archived by the owner on Feb 8, 2020. It is now read-only.

Commit

Permalink
Merge pull request #180 from broidHQ/fix/observable-errors
Browse files Browse the repository at this point in the history
Fix/observable errors
  • Loading branch information
dustinblackman authored Sep 11, 2017
2 parents 50f56c8 + 39f0ac9 commit 2272113
Show file tree
Hide file tree
Showing 124 changed files with 1,497 additions and 952 deletions.
25 changes: 19 additions & 6 deletions broid-alexa/lib/core/Adapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ const utils_1 = require("@broid/utils");
const Promise = require("bluebird");
const events_1 = require("events");
const express_1 = require("express");
const uuid = require("node-uuid");
const R = require("ramda");
const Rx_1 = require("rxjs/Rx");
const uuid = require("uuid");
const Parser_1 = require("./Parser");
const WebHookServer_1 = require("./WebHookServer");
class Adapter {
Expand Down Expand Up @@ -59,13 +59,26 @@ class Adapter {
}
listen() {
return Rx_1.Observable.fromEvent(this.emitter, 'message')
.mergeMap((normalized) => this.parser.parse(normalized))
.mergeMap((parsed) => this.parser.validate(parsed))
.mergeMap((validated) => {
if (!validated) {
.switchMap((value) => {
return Rx_1.Observable.of(value)
.mergeMap((normalized) => this.parser.parse(normalized))
.mergeMap((parsed) => this.parser.validate(parsed))
.mergeMap((validated) => {
if (!validated) {
return Rx_1.Observable.empty();
}
return Promise.resolve(validated);
})
.catch((err) => {
this.logger.error('Caught Error, continuing', err);
return Rx_1.Observable.of(err);
});
})
.mergeMap((value) => {
if (value instanceof Error) {
return Rx_1.Observable.empty();
}
return Promise.resolve(validated);
return Promise.resolve(value);
});
}
send(data) {
Expand Down
6 changes: 3 additions & 3 deletions broid-alexa/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@
"@types/bluebird-global": "^3.5.1",
"@types/moment": "^2.13.0",
"@types/node": "^7.0.12",
"@types/node-uuid": "^0.0.28",
"@types/ramda": "^0.0.5",
"@types/uuid": "^3.0.0",
"ava": "^0.18.1",
"concurrently": "^3.1.0",
"copyfiles": "^1.2.0",
Expand All @@ -65,9 +65,9 @@
"bluebird": "^3.4.7",
"body-parser": "^1.16.0",
"express": "^4.14.0",
"node-uuid": "^1.4.7",
"ramda": "^0.23.0",
"rxjs": "^5.0.2"
"rxjs": "^5.0.2",
"uuid": "^3.1.0"
},
"ava": {
"files": [
Expand Down
28 changes: 21 additions & 7 deletions broid-alexa/src/core/Adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import { Logger } from '@broid/utils';
import * as Promise from 'bluebird';
import { EventEmitter } from 'events';
import { Router } from 'express';
import * as uuid from 'node-uuid';
import * as R from 'ramda';
import { Observable } from 'rxjs/Rx';
import * as uuid from 'uuid';

import { IAdapter, IAdapterOptions } from './interfaces';
import { Parser } from './Parser';
Expand Down Expand Up @@ -90,12 +90,26 @@ export class Adapter implements IAdapter {
// Listen 'message' event from Nexmo
public listen(): Observable<object> {
return Observable.fromEvent(this.emitter, 'message')
.mergeMap((normalized: any) =>
this.parser.parse(normalized))
.mergeMap((parsed) => this.parser.validate(parsed))
.mergeMap((validated) => {
if (!validated) { return Observable.empty(); }
return Promise.resolve(validated);
.switchMap((value: any) => {
return Observable.of(value)
.mergeMap((normalized: any) =>
this.parser.parse(normalized))
.mergeMap((parsed) => this.parser.validate(parsed))
.mergeMap((validated) => {
if (!validated) { return Observable.empty(); }
return Promise.resolve(validated);
})
.catch((err) => {
this.logger.error('Caught Error, continuing', err);
// Return an empty Observable which gets collapsed in the output
return Observable.of(err);
});
})
.mergeMap((value) => {
if (value instanceof Error) {
return Observable.empty();
}
return Promise.resolve(value);
});
}

Expand Down
24 changes: 14 additions & 10 deletions broid-alexa/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -69,20 +69,24 @@
dependencies:
moment "*"

"@types/node-uuid@^0.0.28":
version "0.0.28"
resolved "https://registry.yarnpkg.com/@types/node-uuid/-/node-uuid-0.0.28.tgz#41655b5ce63b2f3374c4e826b4dd21e729058e3d"
dependencies:
"@types/node" "*"
"@types/node@*":
version "8.0.12"
resolved "https://registry.yarnpkg.com/@types/node/-/node-8.0.12.tgz#0560c3e8c9e3da0aa07d0b86e0b0a02b5fd29480"

"@types/node@*", "@types/node@^7.0.12":
"@types/node@^7.0.12":
version "7.0.12"
resolved "https://registry.yarnpkg.com/@types/node/-/node-7.0.12.tgz#ae5f67a19c15f752148004db07cbbb372e69efc9"

"@types/ramda@^0.0.5":
version "0.0.5"
resolved "https://registry.yarnpkg.com/@types/ramda/-/ramda-0.0.5.tgz#8b381e3363de9db3cb89d3b62f23b73cfb56bc0b"

"@types/uuid@^3.0.0":
version "3.0.0"
resolved "https://registry.yarnpkg.com/@types/uuid/-/uuid-3.0.0.tgz#be93b14bcf97f59c079a9e58754960b5efd946c3"
dependencies:
"@types/node" "*"

abbrev@1:
version "1.1.0"
resolved "https://registry.yarnpkg.com/abbrev/-/abbrev-1.1.0.tgz#d0554c2256636e2f56e7c2e5ad183f859428d81f"
Expand Down Expand Up @@ -2413,10 +2417,6 @@ node-status-codes@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/node-status-codes/-/node-status-codes-1.0.0.tgz#5ae5541d024645d32a58fcddc9ceecea7ae3ac2f"

node-uuid@^1.4.7:
version "1.4.8"
resolved "https://registry.yarnpkg.com/node-uuid/-/node-uuid-1.4.8.tgz#b040eb0923968afabf8d32fb1f17f1167fdab907"

nodesecurity-npm-utils@^5.0.0:
version "5.0.0"
resolved "https://registry.yarnpkg.com/nodesecurity-npm-utils/-/nodesecurity-npm-utils-5.0.0.tgz#05aa30de30ca8c845c4048e94fd78e5e08b55ed9"
Expand Down Expand Up @@ -3626,6 +3626,10 @@ uuid@^3.0.0:
version "3.0.1"
resolved "https://registry.yarnpkg.com/uuid/-/uuid-3.0.1.tgz#6544bba2dfda8c1cf17e629a3a305e2bb1fee6c1"

uuid@^3.1.0:
version "3.1.0"
resolved "https://registry.yarnpkg.com/uuid/-/uuid-3.1.0.tgz#3dd3d3e790abc24d7b0d3a034ffababe28ebbc04"

valid-url@^1.0.9:
version "1.0.9"
resolved "https://registry.yarnpkg.com/valid-url/-/valid-url-1.0.9.tgz#1c14479b40f1397a75782f115e4086447433a200"
Expand Down
23 changes: 16 additions & 7 deletions broid-callr/lib/core/Adapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ const Promise = require("bluebird");
const Callr = require("callr");
const EventEmitter = require("events");
const express_1 = require("express");
const uuid = require("node-uuid");
const R = require("ramda");
const Rx_1 = require("rxjs/Rx");
const uuid = require("uuid");
const Parser_1 = require("./Parser");
const WebHookServer_1 = require("./WebHookServer");
class Adapter {
Expand Down Expand Up @@ -86,14 +86,23 @@ class Adapter {
return Rx_1.Observable.throw(new Error('No session found.'));
}
return Rx_1.Observable.fromEvent(this.emitter, 'message')
.mergeMap((event) => this.parser.normalize(event))
.mergeMap((normalized) => this.parser.parse(normalized))
.mergeMap((parsed) => this.parser.validate(parsed))
.mergeMap((validated) => {
if (!validated) {
.switchMap((value) => {
return Rx_1.Observable.of(value)
.mergeMap((event) => this.parser.normalize(event))
.mergeMap((normalized) => this.parser.parse(normalized))
.mergeMap((parsed) => this.parser.validate(parsed))
.mergeMap((validated) => {
if (!validated) {
return Rx_1.Observable.empty();
}
return Promise.resolve(validated);
});
})
.mergeMap((value) => {
if (value instanceof Error) {
return Rx_1.Observable.empty();
}
return Promise.resolve(validated);
return Promise.resolve(value);
});
}
send(data) {
Expand Down
2 changes: 1 addition & 1 deletion broid-callr/lib/core/Parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
const schemas_1 = require("@broid/schemas");
const utils_1 = require("@broid/utils");
const Promise = require("bluebird");
const uuid = require("node-uuid");
const R = require("ramda");
const uuid = require("uuid");
class Parser {
constructor(serviceName, serviceID, logLevel) {
this.serviceID = serviceID;
Expand Down
6 changes: 3 additions & 3 deletions broid-callr/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,15 @@
"body-parser": "^1.15.2",
"callr": "^1.0.0",
"express": "^4.14.0",
"node-uuid": "^1.4.7",
"ramda": "^0.23.0",
"rxjs": "^5.0.2",
"sinon": "^2.1.0"
"sinon": "^2.1.0",
"uuid": "^3.1.0"
},
"devDependencies": {
"@types/node": "^7.0.12",
"@types/node-uuid": "^0.0.28",
"@types/ramda": "^0.0.5",
"@types/uuid": "^3.0.0",
"ava": "^0.17.0",
"concurrently": "^3.1.0",
"copyfiles": "^1.0.0",
Expand Down
23 changes: 16 additions & 7 deletions broid-callr/src/core/Adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import * as Promise from 'bluebird';
import * as Callr from 'callr';
import * as EventEmitter from 'events';
import { Router } from 'express';
import * as uuid from 'node-uuid';
import * as R from 'ramda';
import { Observable } from 'rxjs/Rx';
import * as uuid from 'uuid';

import { IAdapterOptions, ICallrWebHookEvent } from './interfaces';
import { Parser } from './Parser';
Expand Down Expand Up @@ -129,12 +129,21 @@ export class Adapter {
}

return Observable.fromEvent(this.emitter, 'message')
.mergeMap((event: ICallrWebHookEvent) => this.parser.normalize(event))
.mergeMap((normalized) => this.parser.parse(normalized))
.mergeMap((parsed) => this.parser.validate(parsed))
.mergeMap((validated) => {
if (!validated) { return Observable.empty(); }
return Promise.resolve(validated);
.switchMap((value) => {
return Observable.of(value)
.mergeMap((event: ICallrWebHookEvent) => this.parser.normalize(event))
.mergeMap((normalized) => this.parser.parse(normalized))
.mergeMap((parsed) => this.parser.validate(parsed))
.mergeMap((validated) => {
if (!validated) { return Observable.empty(); }
return Promise.resolve(validated);
});
})
.mergeMap((value) => {
if (value instanceof Error) {
return Observable.empty();
}
return Promise.resolve(value);
});
}

Expand Down
2 changes: 1 addition & 1 deletion broid-callr/src/core/Parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import {
import { cleanNulls, fileInfo, isUrl, Logger } from '@broid/utils';

import * as Promise from 'bluebird';
import * as uuid from 'node-uuid';
import * as R from 'ramda';
import * as uuid from 'uuid';

import { ICallrWebHookEvent } from './interfaces';

Expand Down
24 changes: 14 additions & 10 deletions broid-callr/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,24 @@
request "^2.81.0"
valid-url "^1.0.9"

"@types/node-uuid@^0.0.28":
version "0.0.28"
resolved "https://registry.yarnpkg.com/@types/node-uuid/-/node-uuid-0.0.28.tgz#41655b5ce63b2f3374c4e826b4dd21e729058e3d"
dependencies:
"@types/node" "*"
"@types/node@*":
version "8.0.12"
resolved "https://registry.yarnpkg.com/@types/node/-/node-8.0.12.tgz#0560c3e8c9e3da0aa07d0b86e0b0a02b5fd29480"

"@types/node@*", "@types/node@^7.0.12":
"@types/node@^7.0.12":
version "7.0.12"
resolved "https://registry.yarnpkg.com/@types/node/-/node-7.0.12.tgz#ae5f67a19c15f752148004db07cbbb372e69efc9"

"@types/ramda@^0.0.5":
version "0.0.5"
resolved "https://registry.yarnpkg.com/@types/ramda/-/ramda-0.0.5.tgz#8b381e3363de9db3cb89d3b62f23b73cfb56bc0b"

"@types/uuid@^3.0.0":
version "3.0.0"
resolved "https://registry.yarnpkg.com/@types/uuid/-/uuid-3.0.0.tgz#be93b14bcf97f59c079a9e58754960b5efd946c3"
dependencies:
"@types/node" "*"

abbrev@1:
version "1.1.0"
resolved "https://registry.yarnpkg.com/abbrev/-/abbrev-1.1.0.tgz#d0554c2256636e2f56e7c2e5ad183f859428d81f"
Expand Down Expand Up @@ -2557,10 +2561,6 @@ node-status-codes@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/node-status-codes/-/node-status-codes-1.0.0.tgz#5ae5541d024645d32a58fcddc9ceecea7ae3ac2f"

node-uuid@^1.4.7:
version "1.4.8"
resolved "https://registry.yarnpkg.com/node-uuid/-/node-uuid-1.4.8.tgz#b040eb0923968afabf8d32fb1f17f1167fdab907"

nodesecurity-npm-utils@^5.0.0:
version "5.0.0"
resolved "https://registry.yarnpkg.com/nodesecurity-npm-utils/-/nodesecurity-npm-utils-5.0.0.tgz#05aa30de30ca8c845c4048e94fd78e5e08b55ed9"
Expand Down Expand Up @@ -3796,6 +3796,10 @@ uuid@^3.0.0:
version "3.0.1"
resolved "https://registry.yarnpkg.com/uuid/-/uuid-3.0.1.tgz#6544bba2dfda8c1cf17e629a3a305e2bb1fee6c1"

uuid@^3.1.0:
version "3.1.0"
resolved "https://registry.yarnpkg.com/uuid/-/uuid-3.1.0.tgz#3dd3d3e790abc24d7b0d3a034ffababe28ebbc04"

valid-url@^1.0.9:
version "1.0.9"
resolved "https://registry.yarnpkg.com/valid-url/-/valid-url-1.0.9.tgz#1c14479b40f1397a75782f115e4086447433a200"
Expand Down
Loading

0 comments on commit 2272113

Please sign in to comment.