Skip to content
This repository has been archived by the owner on May 24, 2022. It is now read-only.

Fix unhandled transport errors #565

Merged
merged 1 commit into from
Oct 29, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 20 additions & 17 deletions packages/fether-react/src/utils/PostMessageProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
// along with Parity. If not, see <http://www.gnu.org/licenses/>.

import EventEmitter from 'eventemitter3';
import TransportError from '@parity/api/src/transport/error';

import Debug from './debug';
import * as postMessage from './postMessage';
Expand Down Expand Up @@ -62,24 +63,20 @@ export default class PostMessageProvider extends EventEmitter {
}

send (method, params, callback) {
return new Promise((resolve, reject) => {
this._send(
{
method,
params
this._send(
{
method,
params
},
{
resolve: (...argz) => {
callback(null, ...argz);
},
{
resolve: (...argz) => {
resolve(...argz);
callback(null, ...argz);
},
reject: err => {
reject(err);
callback(err);
}
reject: err => {
callback(err);
}
);
});
}
);
}

_methodsFromApi (api) {
Expand Down Expand Up @@ -183,7 +180,13 @@ export default class PostMessageProvider extends EventEmitter {
// request response
const result = parsed.result;
if (error) {
this._messages[id].reject(new Error(error.message));
this._messages[id].reject(
new TransportError(
this._messages[id].method,
error.code,
error.message
)
);
} else {
this._messages[id].resolve(result);

Expand Down