【问题标题】:ColdFusion Problems with Both onError And cferror与 onError 和 cferror 相关的 ColdFusion 问题
【发布时间】:2018-05-16 14:52:11
【问题描述】:

我遇到了一个问题,我的 onError 方法在我的 application.cfc 文件中不再有效。该程序昨天捕获错误并正确显示 error.cfm,但现在我收到 500 错误。我的经理昨天可能更改了文件中的一些内容,但我们似乎重新创建了它,但没有解决任何问题。

我目前使用 onError,但我尝试了 cferror。使用 cferror 甚至无法加载数据输入表单。

代码如下。 onError 被阻止,因为我用 cferror 代码显示它。如果你想使用它,只需删除 cferror 和 blocks 就会出现 onError:

<!--- this component controls the application's global settings / event 
handlers and maintains user sessions --->
<cfcomponent>

  <!--- define some basic settings --->

  <cfset this.name = "QualityDataPortal" />
  <cfset this.sessionManagement = "yes" />
  <cfset this.setClientCookies = "no" />
  <cfset this.loginStorage = "session" />
  <!--- this function is triggered when our application is initialized --->
  <cffunction name="onApplicationStart" access="public" returntype="boolean" output="no">
    <!--- define application variables --->
    <cfset application.dataSource = 'quality' />
    <!--- return out --->
    <cfreturn true />
  </cffunction>
  <cferror
    template="error.cfm"
    type="exception"
    mailTo="Generic@org.edu" />
  <!--- <!--- this function is triggered when coldfusion encounters an error --->
    <cffunction name="onError" access="public" returntype="void" output="no">
      <cfargument name="exception" required="yes">
      <cfargument name="eventname" type="string" required="yes">

      <!--- send a dump of the error via email --->
      <cfmail from="QDP@org.edu" to="Generic@org.edu" subject="Quality Data Portal Error Encountered" type="html">
        <cfoutput>
          The following error was encountered on #dateformat(now(), 'dddd mmmm dd, yyyy')# at #timeformat(now(), 'hh:mm:ss tt')#<br /><br />
          <cfdump var="#arguments.exception#">
          <cftry><cfdump var="#arguments#"><cfcatch></cfcatch></cftry>
          <cfdump var="#form#">
          <cfdump var="#session#">
          <cfdump var="#cgi#">
        </cfoutput>
      </cfmail>

      <!--- alert the user that an error has been encountered --->
      <cflocation url="error.cfm" addtoken="no">
      <cfabort />

    </cffunction> --->

  <!--- this function is triggered when coldfusion receives a request for a template it cannot locate --->
  <cffunction name="onMissingTemplate" access="public" returntype="void" output="no">
    <cfargument name="targetPage" type="string" required="yes">
    <!--- alert the user that the page they requested could not be found --->
    <cflocation url="404.cfm" addtoken="no">
    <cfabort />
    <!--- return out --->
    <cfreturn />
  </cffunction>
</cfcomponent>

【问题讨论】:

  • 500个错误是http,不是coldfusion
  • 我怀疑您的错误处理程序代码引发了错误。取出&lt;cferror &gt; 标签,你不需要它。清空您的onError 函数以至少发送电子邮件。假设可行,开始重新添加代码,直到它再次失败。然后修复它。

标签: javascript html server coldfusion


【解决方案1】:

我建议,为了让你看得更清楚,删除未使用的代码(cferror 标签),删除不必要的 cmets,不要嵌套 cmets。

然后,从onError 的代码开始

<cffunction name="onError" returntype="void" output="false">

    <cfargument name="exception" required="true">
    <cfargument name="eventname" type="string" required="true">

    <cfmail to="Generic@org.edu" from="QDP@org.edu" subject="Quality Data Portal Error Encountered" type="html">

        <cfoutput>The following error was encountered on #DateFormat(now(), "dddd, mmmm dd, yyyy")# at #TimeFormat(now(), "HH:nn:ss")#</cfoutput>
        <hr />
        <cfdump var="#exception#" label="Exception" />        
        <cfdump var="#form#" label="Form" /> 
        <cfdump var="#session#" label="Session" /> 
        <cfdump var="#cgi#" label="CGI" /> 

    </cfmail>

    <cflocation url="error.cfm" addtoken="false" />

</cffunction>

注意:

  • 注意这个:#timeformat(now(), 'hh:mm:ss tt'),它应该使用nn 分钟而不是mm
  • &lt;cflocation ... 之后没有代码,因为 ColdFusion 不会运行它。

停止执行当前页面并打开 ColdFusion 页面或 HTML 文件。 (https://help.adobe.com/en_US/ColdFusion/9.0/CFMLRef/WSc3ff6d0ea77859461172e0811cbec22c24-7cac.html)

【讨论】:

  • 我什至建议最初删除此行&lt;cflocation url="error.cfm" addtoken="false" /&gt;。假设它工作正常,可以添加回该行以查看它是否仍然工作。我怀疑该模板中的代码存在问题。无论如何,我认为从错误处理程序 cflocation 到另一个页面并不是一个好主意。当该页面也出错时,事情会变得一团糟......
  • @Miguel-F,是的,我同意,那里也可能存在问题,它已经进行了更改。
猜你喜欢
  • 1970-01-01
  • 2021-12-22
  • 2015-12-04
  • 1970-01-01
  • 2015-08-26
  • 2021-08-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多