Reporting errors
Once registered using flare.light(), the @flareapp/js client will automatically catch and report:
- Unhandled errors that bubble up to the
windowobject (window.onerror), - Unhandled promise rejections (
window.onunhandledrejection).
This includes most errors in vanilla JavaScript code that isn't wrapped in a try catch block, as well as promises that reject without a .catch() handler.
Errors that are caught by, for example, Axios' catch block, will not be reported automatically. Keep on reading to find out how to send those errors to Flare too.
Reporting caught errors
You can report errors in catch statements or error boundaries using the flare.report() method:
import { flare } from "@flareapp/js";
try {
functionThatMightThrow();
} catch (error) {
flare.report(error);
}
You can also pass an attributes object as the second parameter to attach one-off context to a specific error report:
try {
processOrder(order);
} catch (error) {
flare.report(error, {
'context.custom': { order: { id: order.id, total: order.total } },
});
}
The report method returns a Promise<void> and can be awaited if needed.
Sending logs to Flare
If you don't have an error object, but you just want to send a simple log message to Flare, you can use the reportMessage method instead:
flare.reportMessage('log message');
Like report, reportMessage is async and returns a Promise<void>.
This method has 2 optional parameters: a level string (one of the message levels), and an attributes object. Messages are always grouped under the 'Log' exception class in the Flare dashboard:
flare.reportMessage('Payment retry limit reached', 'warning', {
'context.custom': { retries: 3 },
});
Advanced: manual report creation
For advanced use cases, the Flare client exposes two lower-level methods that let you create and send reports separately:
// Create a report without sending it
const report = await flare.createReportFromError(error);
if (report) {
// Modify the report as needed
report.attributes['context.custom'] = { buildId: 'abc123' };
// Send the report
await flare.sendReport(report);
}
createReportFromError(error, attributes?) returns a Promise<Report | false>. It builds the full report (stacktrace, context) without sending it. Returns false if the error is invalid.
sendReport(report) sends a pre-built report to Flare. The beforeSubmit hook still runs, so you can use it alongside your existing hooks.
Network failures
If a report fails to send (network error, non-201 response), it is logged to console.error and dropped. Reports are not retried or queued. This is by design: a broken error reporter should not crash your application.
Reporting errors caused by browser extensions
By default, Flare ignores errors that are likely caused by browser extensions. If you want to opt out of this behaviour, you may configure the JavaScript client to report them.
import { flare } from "@flareapp/js";
flare.configure({
reportBrowserExtensionErrors: true,
});