Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1 @@
DS_Store
.DS_Store
58 changes: 44 additions & 14 deletions lib/exceptional.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
var HTTP = require('http');
var gzip = require('./gzip').gzip;
var zlib = require('zlib');
var fs = require('fs');

var Exceptional = {
Expand Down Expand Up @@ -57,27 +57,57 @@ var Exceptional = {
},

send_error: function(doc) {
gzip(doc, 1, function(err, data) {

var client = HTTP.createClient(Exceptional.Port, Exceptional.Host);
if(!Buffer.isBuffer(doc))
doc = new Buffer(doc);

zlib.gzip(doc, function (err, data) {
var path = '/api/errors?api_key=' + Exceptional.API_KEY + "&protocol_version=" + Exceptional.PROTOCOL_VERSION;
var request = null;

var headers = {
'Host' : Exceptional.Host,
'Content-Length' : data.length
'Content-Length' : data.length,
'Content-Type' : 'application/json; charset=UTF-8'
};

var request = client.request('POST', '/api/errors?api_key=' + Exceptional.API_KEY + "&protocol_version=" + Exceptional.PROTOCOL_VERSION, headers);
// use feature detection to fallback to deprecated
if (!HTTP.request)
{
// older versions of nodejs use http.createClient
var client = HTTP.createClient(Exceptional.Port, Exceptional.Host);
request = client.request('POST', path, headers);

request.on('response', function (response) {
if (response.statusCode === 200) {
if (Exceptional.VERBOSE) console.log("Error data successfully sent to " + Exceptional.Host + ':' + Exceptional.Port );
} else {
if (Exceptional.VERBOSE) console.log("Error sending to " + Exceptional.Host + ":" + Exceptional.Port + " :" + response.statusCode);
}
});
}
else
{
// newer versions of nodejs use http.request
var options = {
host: Exceptional.Host,
port: Exceptional.Port,
path: path,
method: 'POST',
header: headers
};

request = HTTP.request(options, function(response) {
if (response.statusCode === 200) {
if (Exceptional.VERBOSE) console.log("Error data successfully sent to " + Exceptional.Host + ':' + Exceptional.Port );
} else {
if (Exceptional.VERBOSE) console.log("Error sending to " + Exceptional.Host + ":" + Exceptional.Port + " :" + response.statusCode);
}
});
}

// post the data
request.write(data);
request.end();

request.on('response', function (response) {
if (response.statusCode === 200) {
if (Exceptional.VERBOSE) console.log("Error data successfully sent to exceptional");
} else {
if (Exceptional.VERBOSE) console.log("Error sending to api.getexceptional.com :" + response.statusCode);
}
});
});
}
};
Expand Down
41 changes: 0 additions & 41 deletions lib/gzip/index.js

This file was deleted.