/wheels/events/onerror.cfm

http://cfwheels.googlecode.com/ · ColdFusion · 74 lines · 69 code · 5 blank · 0 comment · 20 complexity · 6953d83bff8ff1e98d61450e7dcc2326 MD5 · raw file

  1. <cffunction name="onError" returntype="void" access="public" output="true">
  2. <cfargument name="exception" type="any" required="true">
  3. <cfargument name="eventName" type="any" required="true">
  4. <cfscript>
  5. var loc = {};
  6. // In case the error was caused by a timeout we have to add extra time for error handling.
  7. // We have to check if onErrorRequestTimeout exists since errors can be triggered before the application.wheels struct has been created.
  8. loc.requestTimeout = 70;
  9. if (StructKeyExists(application, "wheels") && StructKeyExists(application.wheels, "onErrorRequestTimeout"))
  10. loc.requestTimeout = application.wheels.onErrorRequestTimeout;
  11. $setting(requestTimeout=loc.requestTimeout);
  12. loc.returnValue = $simpleLock(execute="$runOnError", executeArgs=arguments, name="wheelsReloadLock", type="readOnly", timeout=180);
  13. </cfscript>
  14. <cfoutput>
  15. #loc.returnValue#
  16. </cfoutput>
  17. </cffunction>
  18. <cffunction name="$runOnError" returntype="string" access="public" output="false">
  19. <cfargument name="exception" type="any" required="true">
  20. <cfargument name="eventName" type="any" required="true">
  21. <cfscript>
  22. var loc = {};
  23. if (StructKeyExists(application, "wheels") && StructKeyExists(application.wheels, "initialized"))
  24. {
  25. if (application.wheels.sendEmailOnError && Len(application.wheels.errorEmailAddress))
  26. {
  27. loc.mailArgs = {};
  28. $args(name="sendEmail", args=loc.mailArgs);
  29. if (StructKeyExists(application.wheels, "errorEmailServer") && Len(application.wheels.errorEmailServer))
  30. loc.mailArgs.server = application.wheels.errorEmailServer;
  31. loc.mailArgs.from = application.wheels.errorEmailAddress;
  32. loc.mailArgs.to = application.wheels.errorEmailAddress;
  33. loc.mailArgs.subject = application.wheels.errorEmailSubject;
  34. loc.mailArgs.type = "html";
  35. loc.mailArgs.tagContent = $includeAndReturnOutput($template="wheels/events/onerror/cfmlerror.cfm", exception=arguments.exception);
  36. StructDelete(loc.mailArgs, "layouts", false);
  37. StructDelete(loc.mailArgs, "detectMultiPart", false);
  38. $mail(argumentCollection=loc.mailArgs);
  39. }
  40. if (application.wheels.showErrorInformation)
  41. {
  42. if (StructKeyExists(arguments.exception, "rootCause") && Left(arguments.exception.rootCause.type, 6) == "Wheels")
  43. loc.wheelsError = arguments.exception.rootCause;
  44. else if (StructKeyExists(arguments.exception, "cause") && StructKeyExists(arguments.exception.cause, "rootCause") && Left(arguments.exception.cause.rootCause.type, 6) == "Wheels")
  45. loc.wheelsError = arguments.exception.cause.rootCause;
  46. if (StructKeyExists(loc, "wheelsError"))
  47. {
  48. loc.returnValue = $includeAndReturnOutput($template="wheels/styles/header.cfm");
  49. loc.returnValue = loc.returnValue & $includeAndReturnOutput($template="wheels/events/onerror/wheelserror.cfm", wheelsError=loc.wheelsError);
  50. loc.returnValue = loc.returnValue & $includeAndReturnOutput($template="wheels/styles/footer.cfm");
  51. }
  52. else
  53. {
  54. $throw(object=arguments.exception);
  55. }
  56. }
  57. else
  58. {
  59. $header(statusCode=500, statusText="Internal Server Error");
  60. loc.returnValue = $includeAndReturnOutput($template="#application.wheels.eventPath#/onerror.cfm", exception=arguments.exception, eventName=arguments.eventName);
  61. }
  62. }
  63. else
  64. {
  65. $throw(object=arguments.exception);
  66. }
  67. </cfscript>
  68. <cfreturn loc.returnValue>
  69. </cffunction>