Collects browser errors, server request errors, and uncaught exceptions, and provides an API for consuming them.
yarn add fusion-plugin-error-handling
// src/monitoring.js
import {createPlugin} from 'fusion-core';
export default __NODE__ && createPlugin({
provides() {
return (e, captureType) => {
if (captureType === 'browser') {
const {message, source, line, col, error} = e;
console.log({message, source, line, col, error});
} else if (captureType === 'server') {
console.log('UNCAUGHT EXCEPTION', e);
} else if (captureType === 'request') {
console.log('REQUEST ERROR');
}
}
}
}
});
Normally, instead of using console
, you would consume errors via something like Kafka or at least use a production logger (such as fusion-plugin-universal-logger
) in conjunction with a logging service such as LogEntries or Papertrail.
// src/main.js
import React from 'react';
import App from 'fusion-react';
import ErrorHandling, {ErrorHandlerToken} from 'fusion-plugin-error-handling';
import log from './monitoring';
export default () => {
const app = new App(<div />);
if (__NODE__) {
app.register(ErrorHandlerToken, log);
app.register(ErrorHandling);
}
return app;
};
import ErrorHandling from 'fusion-plugin-error-handling';
The plugin. Typically doesn't need to be associated with a token.
import {ErrorHandlerToken} from 'fusion-plugin-error-handling';
A function to be called when an error is reported.
type ErrorHandler = (e: Error, captureType: string) => Promise
If the error is a global uncaught exception or unhandled rejection, the process exits when the returned Promise resolves/rejects.
e: Error
- The error that was reportedcaptureType: string
- Either 'browser', 'uncaught' or 'request'.- returns
Promise
fusion-plugin-error-handling's People
Forkers
kevingrandon ganemone rtsao nadiia lhorie steponas derekjuber mlmorg uberopensourcebot angus-c albertywu rajeshsegu cdlewisfusion-plugin-error-handling's Issues
Update request error handler to send early response
Should not panic when older browsers do not provide error objects for `onerror()`
Ref: https://blog.sentry.io/2016/01/04/client-javascript-reporting-window-onerror.html
in server.js:
onerror = function(m,s,l,c,e) {
if (e.__handled) return;
For some clients (e.g., Safari 9.x) the 5th param e
- the error object does not present. We should at least not throw in the meanwhile.
Migrate fusion-plugin-error-handling to DI
Migrate to new fusion-tokens api
Ensure process exits after uncaughtException/unhandledRejection
Remove fusion-cli dependency
Rename "type" to something more descriptive
Migrate documentation to leverage Dependency Injection API
Problem/Rationale
Documentation regarding Fusion API is out of date given recent changes to leverage new Dependency Injection architecture.
Solution/Change/Deliverable
Update documentation (e.g. no .plugin
).
Use Buildkite for CI
Update dependencies
Make ErrorHandlingEmitterToken optional, default to calling window.onError
While we may want to consider syncing this up with the server side error handler,
since their types will be different I think it is safe to keep them separate for now.
We can have the ErrorHandlingEmitterToken be optional since we can safely default to
triggering window.onerror.
Add initial implementation
Fix flow types
Update request error handler to send early response
Ideally the error handler should send a 500 response as
early as possible, without waiting for error reporting
to complete. This will ensure a better experience for the
user as well as fewer active connections being held onto by
the server.
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. ๐๐๐
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google โค๏ธ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.