Added error resolving

This commit is contained in:
hydrabolt
2015-08-26 13:12:51 +01:00
parent 8de0199bf5
commit 206f8cfe1f
2 changed files with 30 additions and 9 deletions

View File

@@ -545,6 +545,17 @@ var Client = (function () {
} else {
fstream = file;
}
self.resolveDestination(destination).then(send)["catch"](error);
function send(destination) {
request.post(Endpoints.CHANNELS + "/" + destination + "/messages");
}
function error(err) {
callback(err);
reject(err);
}
});
}
}, {

View File

@@ -545,23 +545,33 @@ class Client {
}
sendFile(destination, file, callback = function (err, msg) { }) {
var self = this;
return new Promise(function(resolve, reject){
return new Promise(function (resolve, reject) {
var fstream;
if(typeof file === "string" || file instanceof String){
if (typeof file === "string" || file instanceof String) {
fstream = fs.createReadStream(file);
}else{
} else {
fstream = file;
}
self.resolveDestination(destination).then(send).catch(error);
function send(destination) {
request
.post(`${Endpoints.CHANNELS}/${destination}/messages`)
}
function error(err){
callback(err);
reject(err);
}
});
}
sendMessage(destination, message, callback = function (err, msg) { }, premessage = "") {