-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathonerror.cfm
58 lines (49 loc) · 2.08 KB
/
onerror.cfm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<!--- Create the URL string of the page that the error occured on. --->
<cfset errorPage = "#LCase(ListFirst(cgi.server_protocol, "/"))#://#cgi.server_name##Replace(cgi.script_name, "/#application.wheels.rewriteFile#", "")##cgi.path_info#" />
<cfif cgi.query_string IS NOT "">
<cfset errorPage = errorPage & "?#cgi.query_string#" />
</cfif>
<!--- Setup the struct of the data to send to Bugsnag --->
<cfscript>
var payload = {
apiKey = "YOUR_API_KEY_HERE";
notifier = {
name : "Bugsnag Cfwheels",
version : "1.0",
url : errorPage,
},
events = [{
userId : cgi.remote_host,
osVersion : cgi.http_user_agent,
releaseStage : "production",
context : Application.WHEELS.EXISTINGOBJECTFILES,
exceptions = [{
errorClass : arguments.exception.rootcause.type,
message : arguments.exception.rootcause.message,
stacktrace : []
}]
}]
};
for ( s = 1; s LTE arraylen(payload.arguments.exception.rootcause.TagContext); s = s+1 ) {
var trace = {
file : arguments.exception.rootcause.TagContext[s].template,
lineNumber : arguments.exception.rootcause.TagContext[s].line,
columnNumber : arguments.exception.rootcause.TagContext[s].column,
method : arguments.exception.rootcause.TagContext[s].codePrintPlain
};
arrayAppend(payload.events[1].exceptions[1].stacktrace, trace);
}
var jsonPayload = serializejson(payload);
httpService = new http();
httpService.setUrl("https://notify.bugsnag.com");
httpService.setMethod("post");
httpService.addParam(type="header", name="Content-Type", value="application/json");
httpService.addParam(type="body", value=jsonPayload);
result = httpService.send().getPrefix();
</cfscript>
<cfheader statuscode="500" statustext="Internal Server Error">
<h1>Error!</h1>
<p>
Sorry, that caused an unexpected error.<br />
Please try again later.
</p>