-
-
Save femotizo/51a26a5630b5ee9ecbb21a9937e47e24 to your computer and use it in GitHub Desktop.
Revisions
-
kilihorse revised this gist
Jul 16, 2016 . No changes.There are no files selected for viewing
-
kilihorse revised this gist
Jul 16, 2016 . 1 changed file with 11 additions and 5 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -12,7 +12,7 @@ exports.init = function(captrueOnDebugMode){ const originalHandler = global.ErrorUtils.getGlobalHandler(); function errorHandler(e) { exports.issue(e) if (originalHandler) { originalHandler(e); } @@ -58,15 +58,21 @@ exports.log = function(value){ //create a new issue. fileName will be the the error message as the `index.bundle.js` is meaningless exports.issue = function(e){ return StackTrace.fromError(e, {offline: true}).then((stack)=>{ return stack.map(row=>{ let {source, lineNumber} = row; if(!lineNumber){ lineNumber = parseInt(source.split(':').slice(-2, -1)) || 0 } return {fileName: e.message, lineNumber, functionName: source} }) }) .then((stack)=>{ Crashlytics.recordCustomExceptionName(e.message, e.message, stack) }) } exports.crash = function(){ return Crashlytics.crash(); } -
kilihorse revised this gist
Jul 6, 2016 . No changes.There are no files selected for viewing
-
kilihorse created this gist
Jul 6, 2016 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,72 @@ /*global __DEV__*/ import StackTrace from 'stacktrace-js'; const Fabric = require('react-native-fabric'); const { Crashlytics } = Fabric; //call this to start capturing any no-handled errors exports.init = function(captrueOnDebugMode){ if (__DEV__ && !captrueOnDebugMode) { return; } const originalHandler = global.ErrorUtils.getGlobalHandler(); function errorHandler(e) { exports.issue(e); if (originalHandler) { originalHandler(e); } } global.ErrorUtils.setGlobalHandler(errorHandler); } //user: {id: ,name: ,email: } exports.setUser = function(user){ const {id, name, email} = {id: 'anony', name: 'anony', email: 'anony', ...user}; Crashlytics.setUserIdentifier(id+''); Crashlytics.setUserName(name+''); Crashlytics.setUserEmail(email+''); } exports.setAttrs = function(obj){ for(let kk in obj){ exports.setAttr(kk, obj[kk]); } } exports.setAttr = function(key, value){ if(!key) return; if(typeof key !== 'string') key = key + ''; let type = typeof value; if(type==='boolean') Crashlytics.setBool(key, value); else if(type==='number') Crashlytics.setNumber(key, value); else if(type==='string') Crashlytics.setString(key, value); else Crashlytics.setString(key, JSON.stringify(value)); } //things that will be in issue's session logs exports.log = function(value){ if(!value) return; if(value instanceof Error){ value = value.stack || value.message; } if(typeof value !== 'string') value += ''; return Crashlytics.log(value); } //create a new issue. fileName will be the the error message as the `index.bundle.js` is meaningless exports.issue = function(e){ StackTrace.fromError(e).then((stack)=>{ stack = stack.map(row=>{ const {source, lineNumber} = row; return {fileName: e.message, lineNumber, functionName: source} }) Crashlytics.recordCustomExceptionName(e.message, e.message, stack) }); } exports.crash = function(){ return Crashlytics.crash(); }