Skip to content
This repository was archived by the owner on Jan 31, 2025. It is now read-only.

Commit e13fc41

Browse files
author
Daniel Brain
committed
Support error code
1 parent 3d50371 commit e13fc41

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

src/drivers/receive/types.js

+10-2
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,14 @@ export let RECEIVE_MESSAGE_TYPES = {
7979
}, err => {
8080

8181
let error = stringifyError(err).replace(/^Error: /, '');
82+
// $FlowFixMe
83+
let code = err.code;
8284

8385
return respond({
8486
type: CONSTANTS.POST_MESSAGE_TYPE.RESPONSE,
8587
ack: CONSTANTS.POST_MESSAGE_ACK.ERROR,
86-
error
88+
error,
89+
code
8790
});
8891
})
8992

@@ -116,7 +119,12 @@ export let RECEIVE_MESSAGE_TYPES = {
116119
deleteResponseListener(message.hash);
117120

118121
if (message.ack === CONSTANTS.POST_MESSAGE_ACK.ERROR) {
119-
return options.respond(new Error(message.error), null);
122+
let err = new Error(message.error);
123+
if (message.code) {
124+
// $FlowFixMe
125+
err.code = message.code;
126+
}
127+
return options.respond(err, null);
120128
} else if (message.ack === CONSTANTS.POST_MESSAGE_ACK.SUCCESS) {
121129
let data = message.data || message.response;
122130

src/lib/serialize.js

+9-2
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,9 @@ type SerializedError = {
8585
function serializeError(err : mixed) : SerializedError {
8686
return {
8787
__type__: CONSTANTS.SERIALIZATION_TYPES.ERROR,
88-
__message__: stringifyError(err)
88+
__message__: stringifyError(err),
89+
// $FlowFixMe
90+
__code__: err.code
8991
};
9092
}
9193

@@ -177,7 +179,12 @@ export function deserializeMethod(source : CrossDomainWindowType, origin : strin
177179
}
178180

179181
export function deserializeError(source : CrossDomainWindowType, origin : string, obj : Object) : Error {
180-
return new Error(obj.__message__);
182+
let err = new Error(obj.__message__);
183+
if (obj.__code__) {
184+
// $FlowFixMe
185+
err.code = obj.__code__;
186+
}
187+
return err;
181188
}
182189

183190
export function deserializeZalgoPromise(source : CrossDomainWindowType, origin : string, prom : Object) : ZalgoPromise<mixed> {

0 commit comments

Comments
 (0)