2017-03-10 14:17:37 +00:00
|
|
|
// @flow
|
|
|
|
import { NativeModules } from 'react-native';
|
|
|
|
import { Base } from './../base';
|
|
|
|
|
|
|
|
const FirebaseCrash = NativeModules.RNFirebaseCrash;
|
|
|
|
|
2017-04-19 14:16:55 +00:00
|
|
|
export default class Crash extends Base {
|
2017-03-10 14:17:37 +00:00
|
|
|
/**
|
|
|
|
* Logs a message that will appear in a subsequent crash report.
|
|
|
|
* @param {string} message
|
|
|
|
* @param params
|
|
|
|
*/
|
|
|
|
log(message: string): void {
|
|
|
|
FirebaseCrash.log(message);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Logs a message that will appear in a subsequent crash report as well as in logcat.
|
|
|
|
* NOTE: Android only functionality. iOS will just log the message.
|
|
|
|
* @param {string} message
|
|
|
|
* @param {number} level
|
|
|
|
* @param {string} tag
|
|
|
|
*/
|
|
|
|
logcat(level: number, tag: string, message: string): void {
|
|
|
|
FirebaseCrash.logcat(level, tag, message);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Generates a crash report for the given message. This method should be used for unexpected
|
|
|
|
* exceptions where recovery is not possible.
|
|
|
|
* NOTE: on iOS, this will cause the app to crash as it's the only way to ensure the exception
|
|
|
|
* gets sent to Firebase. Otherwise it just gets lost as a log message.
|
2017-03-17 15:41:25 +00:00
|
|
|
* @param {Error} error
|
|
|
|
* @param maxStackSize
|
2017-03-10 14:17:37 +00:00
|
|
|
*/
|
2017-04-04 16:58:20 +00:00
|
|
|
report(error: FirebaseError, maxStackSize: number = 10): void {
|
2017-03-17 15:41:25 +00:00
|
|
|
if (!error || !error.code || !error.message) return;
|
|
|
|
|
|
|
|
let errorMessage = `Message: ${error.message}\r\n`;
|
|
|
|
|
|
|
|
if (error.code) {
|
|
|
|
errorMessage = `${errorMessage}Code: ${error.code}\r\n`;
|
|
|
|
}
|
|
|
|
|
|
|
|
const stackRows = error.stack.split('\n');
|
|
|
|
errorMessage = `${errorMessage}\r\nStack: \r\n`;
|
|
|
|
for (let i = 0, len = stackRows.length; i < len; i++) {
|
|
|
|
if (i === maxStackSize) break;
|
|
|
|
errorMessage = `${errorMessage} - ${stackRows[i]}\r\n`;
|
|
|
|
}
|
|
|
|
|
|
|
|
FirebaseCrash.report(errorMessage);
|
2017-03-10 14:17:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
get namespace(): string {
|
|
|
|
return 'firebase:crash';
|
|
|
|
}
|
|
|
|
}
|