Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save stphnwlkr/db7177faafde5f4c164d842d8e40929e to your computer and use it in GitHub Desktop.
Save stphnwlkr/db7177faafde5f4c164d842d8e40929e to your computer and use it in GitHub Desktop.
public void function onError(required any exception, required string eventname){
//log error
writeLog(file='[LOG FILE NAME]', text='#arguments.exception.message#');
//save error information in a single variable
savecontent variable='errortext' {
writeOutput("An error occurred: http://#cgi.server_name##cgi.script_name#?#cgi.query_string#<br />
Time: #now().dateFormat('short')# :: #now().timeFormat('short')#<br />");
writeDump(var=arguments.exception, label='Error Log');
writeDump(var=form, label='Form Scope');
writeDump(var=url, label='URL Scope');
writeDump(var=cgi, label='CGI Scope');
}
//email the results to your self/admin
cfmail(to="[YOUR EMAIL]", from="[YOUR EMAIL]", subject="Error: #arguments.exception.message#",type="html"){
writeOutput(errortext);
};
location(url="[REDIRECT TO FRIENDLY ERROR PAGE]", addtoken="false");
return;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment