bhartsfield
06/16/2022, 6:12 PMcoldbox create app name=cbtest --noinit skeleton=rest
• Coldbox.cfc already has Echo.onError as the exceptionHandler so just add onError = () => { dump("I'm the echo.fc onError method"); abort; }
to Echo.cfc
• Then just throw an error somewhere... like echo.cfc index()
With ENVIRONMENT=development, you get the onError dump. With ENVIRONMENT=production, you get the core rest response packet (even if you have extended/replaced it with your own)
it doesn't make a difference if it is the global exception handler or an onException interceptor, the result is the same.wil-shiftinsert
06/16/2022, 7:04 PM// If in development and not in testing mode, then show exception template, easier to debug
if (
getSetting( "environment" ) eq "development" && !isInstanceOf(
variables.controller,
"MockController"
)
) {
throw( object = arguments.exception );
}
wil-shiftinsert
06/16/2022, 7:05 PM// Development additions Great for Testing
if ( getSetting( "environment" ) eq "development" ) {
prc.response
.setData( structKeyExists( arguments.exception, "tagContext" ) ? arguments.exception.tagContext : {} )
.addMessage( "Detail: #arguments.exception.detail#" )
.addMessage( "StackTrace: #arguments.exception.stacktrace#" );
}
wil-shiftinsert
06/16/2022, 7:06 PMgetSetting( "environment" )
in this filewil-shiftinsert
06/16/2022, 7:10 PMdev
or something totally different. development
is not a reserved name. The only environment name which is fixed is production
because that’s the default. Although it is very descriptive to use development
of course.wil-shiftinsert
06/16/2022, 7:12 PMbhartsfield
06/17/2022, 1:24 PMwil-shiftinsert
06/17/2022, 4:02 PM