Skip to content

Commit

Permalink
prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
miquelbeltran committed Nov 19, 2024
1 parent 4c701ea commit dc9516f
Show file tree
Hide file tree
Showing 7 changed files with 118 additions and 132 deletions.
54 changes: 30 additions & 24 deletions sdk/src/CrashReporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export default class CrashReporter {
onBeforeSendingCrashReport: BeforeSendHandler | null,
version: string,
maxErrorReportsStoredOnDevice: number,
maxBreadCrumbsPerErrorReport: number,
maxBreadCrumbsPerErrorReport: number
) {
// Assign the values parsed in (assuming initiation is the only time these are altered)
this.apiKey = apiKey;
Expand All @@ -61,10 +61,14 @@ export default class CrashReporter {
this.version = version;

this.maxErrorReportsStoredOnDevice = Math.min(
Math.max(maxErrorReportsStoredOnDevice, 0), CrashReporter.MAX_ERROR_REPORTS_STORED_ON_DEVICE);
Math.max(maxErrorReportsStoredOnDevice, 0),
CrashReporter.MAX_ERROR_REPORTS_STORED_ON_DEVICE
);

this.maxBreadcrumbsPerErrorReport = Math.min(
Math.max(maxBreadCrumbsPerErrorReport, 0), CrashReporter.MAX_BREADCRUMBS_PER_ERROR_REPORT);
Math.max(maxBreadCrumbsPerErrorReport, 0),
CrashReporter.MAX_BREADCRUMBS_PER_ERROR_REPORT
);

if (customCrashReportingEndpoint && customCrashReportingEndpoint.length > 0) {
this.raygunCrashReportEndpoint = customCrashReportingEndpoint;
Expand All @@ -88,14 +92,14 @@ export default class CrashReporter {
polyfillGlobal('Promise', () => {
tracking.enable({
allRejections: true,
onUnhandled: this.processUnhandledRejection.bind(this),
onUnhandled: this.processUnhandledRejection.bind(this)
});

return Promise;
});
}

this.resendCachedReports().then((r) => { });
this.resendCachedReports().then(r => {});
}

/**
Expand Down Expand Up @@ -126,7 +130,6 @@ export default class CrashReporter {
* @param {Breadcrumb} breadcrumb
*/
recordBreadcrumb(breadcrumb: Breadcrumb) {

/**
Android does not seem to handle the mismatched types gracefully like how iOS does.
Therefore we need to an additional check to avoid users app from crashing
Expand Down Expand Up @@ -216,7 +219,7 @@ export default class CrashReporter {
const reCache: CrashReportPayload[] = [];

for (let i = 0; i < cache.length; i++) {
await this.sendCrashReport(cache[i]).then((success) => {
await this.sendCrashReport(cache[i]).then(success => {
if (!success) reCache.push(cache[i]);
});
}
Expand All @@ -231,7 +234,9 @@ export default class CrashReporter {
async setMaxReportsStoredOnDevice(newSize: number) {
// Set the maximum keeping between a range of [0, 64]
this.maxErrorReportsStoredOnDevice = Math.min(
Math.max(newSize, 0), CrashReporter.MAX_ERROR_REPORTS_STORED_ON_DEVICE);
Math.max(newSize, 0),
CrashReporter.MAX_ERROR_REPORTS_STORED_ON_DEVICE
);

// Remove excess cached reports where necessary, prioritising older reports
const cache: CrashReportPayload[] = await this.getCachedCrashReports();
Expand Down Expand Up @@ -318,9 +323,9 @@ export default class CrashReporter {
*/
async managePayload(payload: CrashReportPayload) {
const modifiedPayload =
this.onBeforeSendingCrashReport && typeof this.onBeforeSendingCrashReport === 'function' ?
this.onBeforeSendingCrashReport(Object.freeze(payload)) :
payload;
this.onBeforeSendingCrashReport && typeof this.onBeforeSendingCrashReport === 'function'
? this.onBeforeSendingCrashReport(Object.freeze(payload))
: payload;

if (!modifiedPayload) {
return;
Expand Down Expand Up @@ -366,7 +371,7 @@ export default class CrashReporter {
MethodName: methodName || '[anonymous]',
LineNumber: lineNumber,
ColumnNumber: column,
ClassName: `line ${lineNumber}, column ${column}`,
ClassName: `line ${lineNumber}, column ${column}`
});

return {
Expand All @@ -375,25 +380,25 @@ export default class CrashReporter {
Error: {
ClassName: error?.name || 'Unknown',
Message: error?.message || 'Unknown',
StackTrace: Array.isArray(stackTrace) ?
stackTrace.map(convertToCrashReportingStackFrame) :
[convertToCrashReportingStackFrame(stackTrace)],
StackString: error?.toString() || '',
StackTrace: Array.isArray(stackTrace)
? stackTrace.map(convertToCrashReportingStackFrame)
: [convertToCrashReportingStackFrame(stackTrace)],
StackString: error?.toString() || ''
},
Environment: {
UtcOffset: new Date().getTimezoneOffset() / 60.0,
...environmentDetails,
...environmentDetails
},
Client: {
Name: `raygun4reactnative.${Platform.OS}`,
Version: clientVersion,
Version: clientVersion
},
UserCustomData: this.customData,
Tags: getCurrentTags(),
User: getCurrentUser(),
Breadcrumbs: upperFirst(this.breadcrumbs),
Version: this.version || 'Not supplied',
},
Version: this.version || 'Not supplied'
}
};
}

Expand All @@ -408,17 +413,18 @@ export default class CrashReporter {
method: 'POST',
mode: 'cors',
headers: {
'Content-Type': 'application/json',
'Content-Type': 'application/json'
},
body: JSON.stringify(payload),
body: JSON.stringify(payload)
})
.then((response) => {
.then(response => {
if (response.status === this.RAYGUN_RATE_LIMITING_STATUS_CODE) {
RaygunLogger.w('Unable to send Crash Report payload:', 'Raygun rate limiting');
return false;
}
return true;
}).catch((error) => {
})
.catch(error => {
RaygunLogger.e('Unable to send Crash Report payload:', error.message);
return false;
});
Expand Down
61 changes: 28 additions & 33 deletions sdk/src/RaygunClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,14 @@ import {
ManualCrashReportDetails,
RaygunClientOptions,
RealUserMonitoringTimings,
User,
User
} from './Types';
import {
anonUser,
getCurrentTags,
getCurrentUser,
setCurrentTags,
setCurrentUser,
removeNullFields,
} from './Utils';
import { anonUser, getCurrentTags, getCurrentUser, setCurrentTags, setCurrentUser, removeNullFields } from './Utils';
import CrashReporter from './CrashReporter';
import RealUserMonitor from './RealUserMonitor';
import {NativeModules} from 'react-native';
import { NativeModules } from 'react-native';
import RaygunLogger from './RaygunLogger';
const {RaygunNativeBridge} = NativeModules;
const { RaygunNativeBridge } = NativeModules;

/**
* The RaygunClient is the interface in which this provider publicly shows. The bottom of this page
Expand Down Expand Up @@ -55,7 +48,7 @@ const init = (raygunClientOptions: RaygunClientOptions) => {
return false;
}

options = {...removeNullFields(raygunClientOptions)};
options = { ...removeNullFields(raygunClientOptions) };

// Cleans options with defaults
const {
Expand All @@ -73,7 +66,7 @@ const init = (raygunClientOptions: RaygunClientOptions) => {
ignoredURLs = [],
ignoredViews = [],
maxErrorReportsStoredOnDevice = CrashReporter.MAX_ERROR_REPORTS_STORED_ON_DEVICE,
maxBreadcrumbsPerErrorReport = CrashReporter.MAX_BREADCRUMBS_PER_ERROR_REPORT,
maxBreadcrumbsPerErrorReport = CrashReporter.MAX_BREADCRUMBS_PER_ERROR_REPORT
} = options;

RaygunLogger.init(logLevel);
Expand All @@ -90,13 +83,14 @@ const init = (raygunClientOptions: RaygunClientOptions) => {
onBeforeSendingCrashReport as BeforeSendHandler,
version,
maxErrorReportsStoredOnDevice,
maxBreadcrumbsPerErrorReport);
maxBreadcrumbsPerErrorReport
);

if (!disableNativeCrashReporting) {
RaygunNativeBridge.initCrashReportingNativeSupport(
apiKey,
version,
customCrashReportingEndpoint || CrashReporter.DEFAULT_RAYGUN_CRASH_REPORTING_ENDPOINT,
customCrashReportingEndpoint || CrashReporter.DEFAULT_RAYGUN_CRASH_REPORTING_ENDPOINT
);
}
}
Expand All @@ -109,7 +103,8 @@ const init = (raygunClientOptions: RaygunClientOptions) => {
ignoredURLs,
ignoredViews,
customRealUserMonitoringEndpoint,
version);
version
);

// Add the lifecycle event listeners to the bridge.
RaygunNativeBridge.initRealUserMonitoringNativeSupport();
Expand All @@ -127,7 +122,7 @@ const init = (raygunClientOptions: RaygunClientOptions) => {
*/
const setTags = (...tags: string[]) => {
if (!initialized) {
RaygunLogger.w('\'setTags\' was called before initializing the client');
RaygunLogger.w("'setTags' was called before initializing the client");
return;
}

Expand All @@ -147,7 +142,7 @@ const setTags = (...tags: string[]) => {
*/
const getTags = (): string[] => {
if (!initialized) {
RaygunLogger.w('\'getTags\' was called before initializing the client');
RaygunLogger.w("'getTags' was called before initializing the client");
return [];
}
return getCurrentTags();
Expand All @@ -160,7 +155,7 @@ const getTags = (): string[] => {
*/
const setUser = (user: User | null) => {
if (!initialized) {
RaygunLogger.w('\'setUser\' was called before initializing the client');
RaygunLogger.w("'setUser' was called before initializing the client");
return;
}

Expand All @@ -179,9 +174,9 @@ const setUser = (user: User | null) => {
fullName: '',
identifier: '',
isAnonymous: false,
uuid: '',
uuid: ''
};
Object.assign(newUser, user ? {...user} : anonUser);
Object.assign(newUser, user ? { ...user } : anonUser);

// Update user across the react side
setCurrentUser(newUser);
Expand All @@ -197,7 +192,7 @@ const setUser = (user: User | null) => {
*/
const getUser = (): User => {
if (!initialized) {
RaygunLogger.w('\'getUser\' was called before initializing the client');
RaygunLogger.w("'getUser' was called before initializing the client");
return anonUser;
}
return getCurrentUser();
Expand All @@ -209,7 +204,7 @@ const getUser = (): User => {
*/
const recordBreadcrumb = (breadcrumb: Breadcrumb) => {
if (!crashReportingAvailable()) {
RaygunLogger.w('\'recordBreadcrumb\' was called before initializing the client');
RaygunLogger.w("'recordBreadcrumb' was called before initializing the client");
return;
}

Expand All @@ -222,9 +217,9 @@ const recordBreadcrumb = (breadcrumb: Breadcrumb) => {
level: 'debug',
message: '',
timestamp: Date.now(),
type: 'manual',
type: 'manual'
};
Object.assign(newBreadcrumb, {...breadcrumb});
Object.assign(newBreadcrumb, { ...breadcrumb });

// Ensure that no alternative data can be parsed through and overwrite this only option
newBreadcrumb.type = 'manual';
Expand All @@ -237,7 +232,7 @@ const recordBreadcrumb = (breadcrumb: Breadcrumb) => {
*/
const getBreadcrumbs = (): Breadcrumb[] => {
if (!crashReportingAvailable()) {
RaygunLogger.w('\'getBreadcrumbs\' was called before initializing the client');
RaygunLogger.w("'getBreadcrumbs' was called before initializing the client");
return [];
}
return crashReporter.getBreadcrumbs();
Expand All @@ -248,7 +243,7 @@ const getBreadcrumbs = (): Breadcrumb[] => {
*/
const clearBreadcrumbs = () => {
if (!crashReportingAvailable()) {
RaygunLogger.w('\'clearBreadcrumbs\' was called before initializing the client');
RaygunLogger.w("'clearBreadcrumbs' was called before initializing the client");
return;
}
crashReporter.clearBreadcrumbs();
Expand All @@ -275,7 +270,7 @@ const clearBreadcrumbs = () => {
*/
const sendError = async (error: Error, details?: ManualCrashReportDetails) => {
if (!crashReportingAvailable()) {
RaygunLogger.w('\'sendError\' was called before initializing the client');
RaygunLogger.w("'sendError' was called before initializing the client");
return;
}
await crashReporter.processManualCrashReport(error, details);
Expand All @@ -287,7 +282,7 @@ const sendError = async (error: Error, details?: ManualCrashReportDetails) => {
*/
const setCustomData = (customData: CustomData | null) => {
if (!crashReportingAvailable()) {
RaygunLogger.w('\'setCustomData\' was called before initializing the client');
RaygunLogger.w("'setCustomData' was called before initializing the client");
return;
}
crashReporter.setCustomData(customData ? customData : {});
Expand All @@ -298,7 +293,7 @@ const setCustomData = (customData: CustomData | null) => {
*/
const getCustomData = (): CustomData | null => {
if (!crashReportingAvailable()) {
RaygunLogger.w('\'getCustomData\' was called before initializing the client');
RaygunLogger.w("'getCustomData' was called before initializing the client");
return null;
}
return crashReporter.getCustomData();
Expand All @@ -310,7 +305,7 @@ const getCustomData = (): CustomData | null => {
*/
const setMaxReportsStoredOnDevice = (size: number) => {
if (!crashReportingAvailable()) {
RaygunLogger.w('\'setMaxReportsStoredOnDevice\' was called before initializing the client');
RaygunLogger.w("'setMaxReportsStoredOnDevice' was called before initializing the client");
return;
}
crashReporter.setMaxReportsStoredOnDevice(size);
Expand All @@ -334,7 +329,7 @@ const crashReportingAvailable = (): boolean => {
*/
const sendRUMTimingEvent = (eventType: RealUserMonitoringTimings, name: string, durationMs: number) => {
if (!realUserMonitoringAvailable()) {
RaygunLogger.w('\'sendRUMTimingEvent\' was called before initializing the client');
RaygunLogger.w("'sendRUMTimingEvent' was called before initializing the client");
return;
}
realUserMonitor.sendCustomRUMEvent(eventType, name, durationMs);
Expand Down Expand Up @@ -363,5 +358,5 @@ export {
getCustomData,
sendError,
setMaxReportsStoredOnDevice,
sendRUMTimingEvent,
sendRUMTimingEvent
};
4 changes: 2 additions & 2 deletions sdk/src/RaygunLogger.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {LogLevel} from './Types';
import { LogLevel } from './Types';

const pj = require('../package.json');

Expand Down Expand Up @@ -85,7 +85,7 @@ export default class RaygunLogger {
'off' will always be -1, so subtracting any index from off will return a negative (as indexs are
*/
if (levelIndex === -1 || (this.logLevel - levelIndex) < 0) return;
if (levelIndex === -1 || this.logLevel - levelIndex < 0) return;

/*
If this is a valid log level, then match it with the console command array.
Expand Down
Loading

0 comments on commit dc9516f

Please sign in to comment.