Skip to content

Instantly share code, notes, and snippets.

@kevindb
Created October 21, 2016 16:58
Show Gist options
  • Save kevindb/714ccbdc5c57263d1882c587b29a3609 to your computer and use it in GitHub Desktop.
Save kevindb/714ccbdc5c57263d1882c587b29a3609 to your computer and use it in GitHub Desktop.
Elements of a CF Application
component displayname="exception" output=false {
public struct function handleException(
required exception,
boolean log = true,
numeric loadTime = 0
){
transaction action="rollback";
local.trace = this.getTrace(arguments.exception);
if (len(local.trace) > 0) {
lock scope="request" timeout="10" {
request.trace = local.trace;
}
}
if (arguments.log == true) {
application.oLog.error(exception=arguments.exception);
}
local.response = new remoteProxy().newAPIResponse();
local.response.success = false;
local.errorMessage = this.getErrorFromException(arguments.exception);
arrayAppend(local.response.errors, local.errorMessage);
writeDump(var="#arguments.exception#");
return local.response;
}
public string function getErrorFromException(
required exception
){
local.response = "";
local.messageExists = structKeyExists(arguments.exception, "message") && len(arguments.exception.message) gt 0;
local.detailExists = structKeyExists(arguments.exception, "detail") && len(arguments.exception.detail) gt 0;
if (local.messageExists)
local.response &= arguments.exception.message;
if (local.messageExists && local.detailExists)
local.response &= " ";
if (local.detailExists)
local.response &= arguments.exception.detail;
return local.response;
}
public string function getTrace(
required exception
){
local.response = "";
if (structKeyExists(arguments.exception, "tagContext") && arrayLen(arguments.exception.tagContext) gt 0) {
if (structKeyExists(arguments.exception.tagContext[1], "raw_trace") and len(arguments.exception.tagContext[1].raw_trace)) {
local.response &= listLast(arguments.exception.tagContext[1].raw_trace, "$");
}
}
return local.response;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment