Comments (3)
Perhaps using our own setup would be of some use to see if this is worth discussion. Forgive the CoffeeScript if it isn't your thing.
In our case, errors that aren't trivial field validation issues bubble up to the 4-arity handlers for disposition. We've got an error convenience module that wraps the common error codes, and, in the case of anything that'd generate a 500 error, captures a stack trace at the point of instantiation. Therefore any error with a stack present means that Bad Things have happened; any error without one is simply something like a bad request, unauthorized, etc., to send back to the client.
Our setup looks like this. One way to handle the problem, anyway; would be nice to see alternatives, best practices, etc., from the PM2 perspective.
instance = express()
# Various additional middleware setup steps here...
require('routes') instance
# No routes matched handler; create a 404 error and send it on to the
# subsequent handlers for disposition.
instance.use (req, res, next) -> next new error.NotFound()
# Return the best status code we can given the provided error and response
# objects. If the error has a status set, then use that. Otherwise, if
# the response object has a status code, then use that. If neither object
# has anything useful, then use 500.
#
# If the request is an XHR, then handle it by sending the error status
# and message to the client; if it's not an XHR, then just render the
# page for client side processing to handle.
#
# If the error contains a stack trace, send it on for further handling,
# otherwise, we're done here.
instance.use (err, req, res, next) ->
res.status err.status or res.statusCode or 500
if req.xhr
res.send err.message
else
res.render 'index',
csrf: req.csrfToken()
return next err if err.stack
return
# Error contained a stack trace; report it to the management system.
instance.use pmx.expressErrorHandler()
# Final error disposition; error contains a stack trace, so something
# unexpected has happened. Log it for posterity just in case the
# management system wasn't available, and we're done with handling.
instance.use (err, req, res, next) ->
console.error err.stack
return
from pmx.
+1
from pmx.
https://github.com/keymetrics/pmx#add-verbosity-to-an-alert-express-error-handler
from pmx.
Related Issues (20)
- Meter alert properties not returned HOT 4
- Pmx metric average over 60 secods
- Add quality control?
- Ports option will never change from 'N/A'
- Do not report probes that are instantiated but never used HOT 1
- pmx.emit an array fail to send it to km HOT 2
- Probe: Add type + Add retetention
- Human readable format for v8 metrics
- cannot find module semver HOT 3
- PMX not registering custom metrics when starting the app with npm start HOT 1
- Error message: Probe Active handles has reached value null HOT 1
- delete a metric HOT 1
- Disable automatic `Dependencies.collect`
- nodejs not detecting even though installed with npm HOT 1
- Metrics not being reported by pm2 show x HOT 4
- os.tmpDir() is deprecated. Use os.tmpdir() instead HOT 2
- Memory Leak
- Add webpack support HOT 4
- Transaction Tracing fail HOT 3
- [email protected] release issue HOT 9
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.
from pmx.