Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

callback with error for response.sendFile

  • Loading branch information...
commit 49463992b6ef6f2c18c80c0c39dc51534f48020e 1 parent 28f22a6
@Shogun147 authored
Showing with 12 additions and 14 deletions.
  1. +12 −14 lib/response.js
View
26 lib/response.js
@@ -84,14 +84,6 @@ response.format = function(obj) {
return this;
}
-response.attachment = function(filename) {
- if (filename) { this.type(extname(filename)); }
-
- this.set('Content-Disposition', filename ? 'attachment; filename="'+ basename(filename) +'"' : 'attachment');
-
- return this;
-}
-
response.set =
response.header = function(name, value) {
if (arguments.length === 2) {
@@ -313,6 +305,14 @@ response.jsonp = function(status, obj) {
return this.send(body);
}
+response.attachment = function(filename) {
+ if (filename) { this.type(extname(filename)); }
+
+ this.set('Content-Disposition', filename ? 'attachment; filename="'+ basename(filename) +'"' : 'attachment');
+
+ return this;
+}
+
response.sendFile = function(status, path, headers, callback) {
if (typeof(status) === 'string') {
callback = headers; headers = path; path = status; status = 200;
@@ -324,17 +324,15 @@ response.sendFile = function(status, path, headers, callback) {
var promise = fileServer.serveFile(path, status, headers || {}, this.request, this);
- promise.on('error', callback || function(error) {
- // send error to response from here?
- // this.writeHead(500);
- // this.end(statusCodes[500]);
- console.log('SendFileError:');
- console.log(error);
+ promise.on('error', function(error) {
+ callback && callback(error);
});
promise.on('success', function(result) {
callback && callback(null, result);
});
+
+ return this;
}
response.download = function(path, filename, callback) {
Please sign in to comment.
Something went wrong with that request. Please try again.