Skip to content

Commit

Permalink
fix: error handling, logging
Browse files Browse the repository at this point in the history
  • Loading branch information
zetxx committed Dec 27, 2019
1 parent 8278d53 commit 72316ab
Showing 1 changed file with 21 additions and 6 deletions.
27 changes: 21 additions & 6 deletions lib/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,21 +116,36 @@ class Brid {
request: async(destination, message, metaParams = {}) => {
this.log('trace', {in: 'base.getInternalCommunicationContext.request', destination, message, metaParams, meta: getSerializableMeta(meta)});
var globTraceId = this.getGlobTraceId(meta);
return this.remoteApiRequest({destination, message, meta: Object.assign({}, meta, {globTraceId}, metaParams, {isNotification: 0})});
try {
return await this.remoteApiRequest({destination, message, meta: Object.assign({}, meta, {globTraceId}, metaParams, {isNotification: 0})});
} catch (e) {
this.log('error', {
in: 'base.getInternalCommunicationContext.request.response',
destination,
error: e,
message,
metaParams,
meta: getSerializableMeta(meta)
});
throw e;
}
},
notification: async(destination, message, metaParams = {}) => {
this.log('trace', {in: 'base.getInternalCommunicationContext.notification', destination, message, metaParams, meta: getSerializableMeta(meta)});
var globTraceId = this.getGlobTraceId(meta);
this.remoteApiRequest({destination, message, meta: Object.assign({}, meta, {globTraceId}, metaParams, {isNotification: 1})})
.catch((error) => this.log('error', {
try {
this.remoteApiRequest({destination, message, meta: Object.assign({}, meta, {globTraceId}, metaParams, {isNotification: 1})})
} catch (error) {
this.log('error', {
in: 'base.getInternalCommunicationContext.notification.response',
description: 'error should be handled correctly',
destination,
error,
message,
metaParams,
meta: getSerializableMeta(meta)
}));
});
}
return {};
},
getState: (...arg) => this.getStore(...arg),
Expand Down Expand Up @@ -236,7 +251,7 @@ class Brid {
// call api response
return this.apiResponseReceived({result: fnExtResult, meta});
} catch (e) {
this.log('error', {in: 'base.externalIn:userDefinedTransformation', result, error, meta: getSerializableMeta(meta)});
this.log('error', {in: 'base.externalIn:userDefinedTransformation', error: e, meta: getSerializableMeta(meta)});
// call api response with error
return this.apiResponseReceived({error: e, meta});
}
Expand All @@ -263,7 +278,7 @@ class Brid {
this.log('info', {in: 'base.externalIn', description: 'external request is NOT response of api request > don\'t send response to external because user transform function returned false', result, error, meta: getSerializableMeta(meta), transformedMsg});
return {...message, meta: Object.assign({deadIn: 1}, meta)};
} catch (e) {
this.log('error', {in: 'base.externalIn', result, error, meta: getSerializableMeta(meta)});
this.log('error', {in: 'base.externalIn', error: e, meta: getSerializableMeta(meta)});
return this.externalOut({error: e, meta});
}
} else {
Expand Down

0 comments on commit 72316ab

Please sign in to comment.