Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add support for passing in request URL, component and action.

  • Loading branch information...
commit acf85e8c4c52d438bfa73ee8caba50dbedf4bd89 1 parent 6de3834
@tristandunn tristandunn authored
View
22 lib/hoptoad-notifier.js
@@ -1,7 +1,7 @@
var HTTP = require('http');
var Hoptoad = {
VERSION : '0.1.0',
- NOTICE_XML : '<?xml version="1.0" encoding="UTF-8"?><notice version="2.0"><api-key>API_KEY</api-key><notifier><name>node-hoptoad-notifier</name><version>0.1.0</version><url>http://github.com/tristandunn/node-hoptoad-notifier</url></notifier><error><class>EXCEPTION_CLASS</class><message>EXCEPTION_MESSAGE</message><backtrace>BACKTRACE_LINES</backtrace></error><server-environment><project-root>PROJECT_ROOT</project-root><environment-name></environment-name></server-environment></notice>',
+ NOTICE_XML : '<?xml version="1.0" encoding="UTF-8"?><notice version="2.0"><api-key>API_KEY</api-key><notifier><name>node-hoptoad-notifier</name><version>0.1.0</version><url>http://github.com/tristandunn/node-hoptoad-notifier</url></notifier><error><class>EXCEPTION_CLASS</class><message>EXCEPTION_MESSAGE</message><backtrace>BACKTRACE_LINES</backtrace></error><request><url>REQUEST_URL</url><component>REQUEST_COMPONENT</component><action>REQUEST_ACTION</action></request><server-environment><project-root>PROJECT_ROOT</project-root><environment-name></environment-name></server-environment></notice>',
BACKTRACE_MATCHER : /\s+at (.*) \(([^\:]+)\:(\d+)\:(\d+)\)/,
root : process.cwd(),
backtrace_filters : [/hoptoad-notifier\.js/],
@@ -79,12 +79,24 @@ var Hoptoad = {
},
generateXML: function(error) {
- var xml = Hoptoad.NOTICE_XML;
- var root = Hoptoad.escapeText(Hoptoad.root);
- var type = Hoptoad.escapeText(error.type || 'Error');
- var message = Hoptoad.escapeText(error.message || 'Unknown error.');
+ var xml = Hoptoad.NOTICE_XML;
+ var root = Hoptoad.escapeText(Hoptoad.root);
+
+ var url = Hoptoad.escapeText(error.url || '');
+ var type = Hoptoad.escapeText(error.type || 'Error');
+ var action = Hoptoad.escapeText(error.action || '');
+ var message = Hoptoad.escapeText(error.message || 'Unknown error.');
+ var component = Hoptoad.escapeText(error.component || '');
var backtrace = Hoptoad.generateBacktrace(error);
+ if (url.trim() == '' && component.trim() == '') {
+ xml = xml.replace(/<request>.*<\/request>/, '');
+ } else {
+ xml = xml.replace('REQUEST_URL', url)
+ .replace('REQUEST_ACTION', action)
+ .replace('REQUEST_COMPONENT', component);
+ }
+
return xml.replace('PROJECT_ROOT', root)
.replace('EXCEPTION_CLASS', type)
.replace('EXCEPTION_MESSAGE', message)
View
19 spec/fixtures/notice.xml
@@ -1,18 +1 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<notice version="2.0">
- <api-key>API_KEY</api-key>
- <notifier>
- <name>node-hoptoad-notifier</name>
- <version>0.1.0</version>
- <url>http://github.com/tristandunn/node-hoptoad-notifier</url>
- </notifier>
- <error>
- <class>EXCEPTION_CLASS</class>
- <message>EXCEPTION_MESSAGE</message>
- <backtrace>BACKTRACE_LINES</backtrace>
- </error>
- <server-environment>
- <project-root>PROJECT_ROOT</project-root>
- <environment-name>production</environment-name>
- </server-environment>
-</notice>
+<?xml version="1.0" encoding="UTF-8"?><notice version="2.0"><api-key>API_KEY</api-key><notifier><name>node-hoptoad-notifier</name><version>0.1.0</version><url>http://github.com/tristandunn/node-hoptoad-notifier</url></notifier><error><class>EXCEPTION_CLASS</class><message>EXCEPTION_MESSAGE</message><backtrace>BACKTRACE_LINES</backtrace></error><request><url>REQUEST_URL</url><component>REQUEST_COMPONENT</component><action>REQUEST_ACTION</action></request><server-environment><project-root>PROJECT_ROOT</project-root><environment-name>production</environment-name></server-environment></notice>
View
21 spec/unit/spec.js
@@ -255,5 +255,26 @@ JSpec.describe('Hoptoad', function() {
xml.should.match(matcher);
});
+
+ it('should include URL and component', function() {
+ var xml = Hoptoad.generateXML({ url : '/', component : 'Home' });
+ var matcher = new RegExp('<request><url>/</url><component>Home</component>.*</request>');
+
+ xml.should.match(matcher);
+ });
+
+ it('should remove request if no URL and component provided', function() {
+ var xml = Hoptoad.generateXML({});
+ var matcher = new RegExp('<request>.*</request>');
+
+ xml.should_not.match(matcher);
+ });
+
+ it('should include action', function() {
+ var xml = Hoptoad.generateXML({ url : '/', component : 'Home', action : 'index' });
+ var matcher = new RegExp('<request>.*<action>index</action>.*</request>');
+
+ xml.should.match(matcher);
+ });
});
});
Please sign in to comment.
Something went wrong with that request. Please try again.