@@ -25,48 +25,56 @@ await Exceptionless.startup((c) => {
2525 } ;
2626} ) ;
2727
28- app . get ( "/" , function index ( req , res ) {
29- Exceptionless . submitLog ( "loading index content" ) ;
28+ app . get ( "/" , async ( req , res ) => {
29+ await Exceptionless . submitLog ( "loading index content" ) ;
3030 res . send ( "Hello World!" ) ;
3131} ) ;
3232
33- app . get ( "/about" , function about ( req , res ) {
34- Exceptionless . submitFeatureUsage ( "about" ) ;
33+ app . get ( "/about" , async ( req , res ) => {
34+ await Exceptionless . submitFeatureUsage ( "about" ) ;
3535 res . send ( "About" ) ;
3636} ) ;
3737
3838app . get ( "/boom" , function boom ( req , res ) {
3939 throw new Error ( "Boom!!" ) ;
4040} ) ;
4141
42- app . get ( "/trycatch" , function trycatch ( req , res ) {
42+ app . get ( "/trycatch" , async ( req , res ) => {
4343 try {
4444 throw new Error ( "Caught in try/catch" ) ;
4545 } catch ( error ) {
46- Exceptionless . submitException ( error ) ;
47- res . status ( 404 ) . send ( "Error caught in try/catch" ) ;
46+ await Exceptionless . createException ( error )
47+ . addRequestInfo ( req )
48+ . submit ( ) ;
49+
50+ res . status ( 500 ) . send ( "Error caught in try/catch" ) ;
4851 }
4952} ) ;
5053
51- app . use ( function ( err , req , res , next ) {
52- Exceptionless . createUnhandledException ( err , "express" )
54+ app . use ( async ( err , req , res , next ) => {
55+ if ( res . headersSent ) {
56+ return next ( err )
57+ }
58+
59+ await Exceptionless . createUnhandledException ( err , "express" )
5360 . addRequestInfo ( req )
5461 . submit ( ) ;
62+
5563 res . status ( 500 ) . send ( "Something broke!" ) ;
5664} ) ;
5765
58- app . use ( function ( req , res , next ) {
59- Exceptionless . createNotFound ( req . originalUrl ) . addRequestInfo ( req ) . submit ( ) ;
66+ app . use ( async ( req , res ) => {
67+ await Exceptionless . createNotFound ( req . originalUrl ) . addRequestInfo ( req ) . submit ( ) ;
6068 res . status ( 404 ) . send ( "Sorry cant find that!" ) ;
6169} ) ;
6270
63- const server = app . listen ( 3000 , function ( ) {
71+ const server = app . listen ( 3000 , async ( ) => {
6472 var host = server . address ( ) . address ;
6573 var port = server . address ( ) . port ;
6674
6775 var message = "Example app listening at http://" + host + port ;
6876 console . log ( message ) ;
69- Exceptionless . submitLog ( "app" , message , "Info" ) ;
77+ await Exceptionless . submitLog ( "app" , message , "Info" ) ;
7078} ) ;
7179
7280export default app ;
0 commit comments