Hi again,
In a development environment, when an error happens, i want my application to crash and print the stack trace to the console. But the error gets catched and absorbed by an intern error handler, if it happens in between application actions (like when executing the load method of a custom data loader). Is there a way to turn off that error handler?
Best Regards,
Alex (<PROJECT_NAME> team)
Hi Alexander,
You are right. The Bap Client at the moment catches errors, that are thrown in internal sagas and a lot of bap functionality lies there. The errors are handled by an internal platform saga called “logActivityErrorSaga”.
Additionally, the normal js errors e.g. created with new Error("foo") are not logged correctly at the moment. I created a bug ticket for this: <INTERNAL_LINK>
One solution would be to overwrite the platform saga logActivityErrorSaga() in your code.
An internal platform saga can be overwritten by adding a custom platform saga in the additionalPlatformSagas array in your app setup. This saga has to handle the same action as the internal platform saga. It will have precedence over the internal platform saga. The internal platform saga will not be triggered anymore.
This is a difference to the normal sagas, which react to actions addtionally to other already registered sagas. Such sagas can be added via the “customSagas” extension point in the app setup.
In your custom platform saga, that also receives the error object via the error action payload, you can do whatever you need.
An example:
// This is the one that needs to be added in the app setup
function customLogActivityErrorSaga(): ApplicationSaga.Descriptor {
return {
canHandle: (ad: Activity.Descriptor, action: AnyAction) => {
return ActivityActions.error.match(action);
},
handle: (action: Action<ActivityActions.ErrorPayload>) => {
return customLogActivityError(action);
}
};
}
function* customLogActivityError(action: Action<ActivityActions.ErrorPayload>): SagaIterator {
const { activityId, error, operationType } = action.payload;
const errorMessage =`Foo Error: ${error.messge}\nStackTrace: ${error.stack}`;
LoggerFactory.getLogger("application").error(errorMessage);
}
Regarding letting the app crash early: I’m not sure how this could be achieved in an easy way at the moment. Maybe someone else knows a solution for this.
Note: “additionalPlatformSagas” will be renamed to “overridePlatformSagas” in bap 3.0.0