Is there a reason why console.error(error) (more precisely the error.message value) differs between iOS and Android in Ionic Angular app (cordova) ?
I wrote these lines to get an exception:
const a = null;
a.top();
then console.error(error) in my ErrorHandler.
The output for Android seems good but output for iOS is not clear enough.
And I think this is the reason why the stack trace is not correctly built on Rollbar.
Example of output:
Android
iOS
Logs differ in terms on the trace, for Android each trace starts with 'at ...' and ends with file name but for iOS all the error goes on one line with 'step@' instead of 'at' and there is no link to go the file.
Anyone has an idea why this is the case.
- Cordova: 10.0.0
- cordova-ios: 6.1.0
- Angular: 8.0.0
SOLUTION
The error was thrown from an async method. Thus Angular's ErrorHandler catches error thrown from non awaited async methods and returns the error as a Promise.
Therefore in the handleError() method, add the line below
if (error.promise && error.rejection) { error = error.rejection; }
// handle your error
Found this solution thanks to:
Angular custom error handler not getting error type from promise
Full answer below.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…