A constructed object, this module is a Singleton due to the architecture of Raven JS. See [Errors](#Errors) for the publicly available interface.
The initialised state of the object.
Create a new Logger class. Used internally by [Errors](#Errors).
Describes the logging levels available
No logging at all occurs, each call to errors.log or errors.log are no-ops
Logs are stored in a buffer, by default the last 10 lines. When an error occurs, these log lines are attached to the error object.
Logs are stored in the buffer as with `contextonly` however, they are also passed through to the relevant `console.*` API.
Logging only occurs in the console. Raven client is not initialised.
Initialises the Error object with a Raven dependency.
All options are optional, if a configuration option is missing, the module will try to initialise using any configuration found in the DOM using the script config tag.
<!-- DOM configuration settings -->
<script type="application/json" data-o-errors-config>
{
"sentryEndpoint": "https://dsn@app.getsentry.com/123"
}
</script>
Report an Error object to the error aggregator.
// Reports a caught Error generated by the Promise
fetch('example.com').then(doSomething).catch(oErrors.report);
// Reports and re-throws the caught error
try {
doSomething();
} catch(e) {
throw oErrors.report(e);
}
Log an 'ERROR' level log. Intended to have the same semantics as console.error.
This.stores the log in memory and will attach the last n
log lines to the
context of any reported errors. See Errors#log to log a log
message.
Log a 'WARN' level log. Intended to have the same semantics as
console.warn.
This stores the log in memory and will attach the last n
log lines to the
context of the error. See Errors#log to log a log message.
Log a 'LOG' level log. Intended to have the same semantics as console.log.
This stores the log in memory and will attach the last n
log lines to the
context of the error. See Errors#warn to log a warn message.
Wrap a function so that any uncaught errors are caught and reported to the error aggregator.
// Wraps function, any errors occurring within the function are caught, logged, and rethrown.
let wrappedFunction = oErrors.wrap(function() {
throw new Error("My Error");
});
If you want to attach additional contextual information to the error, see
{@link Errors#wrapWithContext}.
-
Wrap a function so that any uncaught errors are caught and reported to the error aggregator. This method allows additional context to be attached to the error if it occurs.
// Wrap a function with some additional context to be reported in the event
// `doSomethingCallback` throws an error.
setTimeout(oErrors.wrapWithContext({ "context:url": "example.com" }, doSomethingCallback), 1000);
Remove the oErrors.log
event listener and clean up as much of the Raven
client as possible.
Errors is unusable after a call to destroy and calling init
subsequently
will fail.