180 likes | 309 Views
Multi-level Error Handling. and logging within the ColdBox Platform. Kalen Gibbons. President of Sercossa Inc. A member of Team ColdBox. Co-Manager of IECFUG Flex, ColdFusion, JavaScript Developer. Catching Exceptions. Exception Levels. Process Level
E N D
Multi-level Error Handling and logging within the ColdBox Platform
Kalen Gibbons President of Sercossa Inc. A member of Team ColdBox Co-Manager of IECFUG Flex, ColdFusion, JavaScript Developer
Exception Levels • Process Level • Manually handling anticipated errors per process • Try/catch blocks and transaction blocks • Handler Level • Catches all exceptions that occur at the handler level • Framework Level • Catch-all for uncaught exceptions from lower layers • Application Level • Last resort, a global handler for when even the framework is failing
Process Level • Custom exception handling • For processes that are likely to fail • Use standard try/catch blocks • Example: anticipating failures • Example: database transaction
Handler Level • Use onErrorconvention • function onError(event, action, exception) • Will handle majority of errors • Example: Model errors bubble up • Useful for catching errors specific to the handler • Example: REST handlers
Framework Level • Catch-all (almost) for your application • Handles uncaught exceptions & those outside the scope of the handlers • Example: exception in interceptor
Application Level • Absolute last resort • Useful when even the framework itself cannot run • No framework resource can be used • Example: Configuration issue
Now What? what to do with captured exceptions Handle the issue to minimize disruption Log the Problem
Minimizing Disruption A case study • Beta Users • Some users who have been accepted into a “beta” program receive early access to new features • The beta program is part of a SAAS solution • Your application uses a REST API provided by the SAAS solution to determine what features to show the user • If the SAAS solution has an outage, how does your application handle the exception?
The Conundrum Log the error or respond gracefully? • Error need to bubble up to hit our logging code • This will terminate request • Handle the failure in the code • Then the error is not logged • It doesn’t have to be one or the other • ColdBox Interceptors • Announce event within the app • More flexibility than using LogBox directly
Interceptor for Logging • Update all levels of error handling to announce the same event • Creates a centralized location for error logging • Attach as many interceptors as you need
Managing Logs Get the most of your exception data
Logging & Tracking Log Files Sending Emails • Is manageable • Is persistent • Is searchable • Allow notifications • Is manageable • Is persistent • Is searchable • Allow notifications Logging to Database Leveraging 3rd Party • Is manageable • Is persistent • Is searchable • Allow notifications • Is manageable • Is persistent • Is searchable • Allow notifications
3rd Party Logging • Consolidated logs from various sources • Server, application, etc. • Easy searching and reporting • Scalability and maintenance • Monitoring and notifications • Set thresholds to be notified of trouble • Monitor for specific events • Be notified of new (first-time) errors to quickly resolve new problems
Logging Solutions • Logglyhttp://loggly.com/ • Amazon SimpleDBhttp://aws.amazon.com/simpledb/usecases_logging/ • LogClarityhttp://www.logfidelity.com/products.asp • EM7http://www.sciencelogic.com/em7-overview • Many More
Putting it all Together Handle errors on Many Levels Log Intelligently • Process • Handler • Framework • Application • Announce events at the top 3 levels • Handler Application level error manually • Don’t interrupt your request to log problems • Choose a solution that’ll help you get the most out of your exception data.
Thanks Kalen@Sercossa.com @KalenGibbons