Changed all error handling to async-stacktrace style + fixed import/export on unix

This commit is contained in:
Peter 'Pita' Martischka 2011-12-04 16:50:02 +01:00
parent db1ba6a65e
commit 5c56e62d67
18 changed files with 325 additions and 352 deletions

View file

@ -18,6 +18,7 @@
* limitations under the License.
*/
var ERR = require("async-stacktrace");
var padManager = require("./PadManager");
var padMessageHandler = require("../handler/PadMessageHandler");
var readOnlyManager = require("./ReadOnlyManager");
@ -109,11 +110,7 @@ exports.getText = function(padID, rev, callback)
//get the pad
getPadSafe(padID, true, function(err, pad)
{
if(err)
{
callback(err);
return;
}
if(ERR(err, callback)) return;
//the client asked for a special revision
if(rev !== undefined)
@ -128,12 +125,11 @@ exports.getText = function(padID, rev, callback)
//get the text of this revision
pad.getInternalRevisionAText(rev, function(err, atext)
{
if(!err)
{
data = {text: atext.text};
}
if(ERR(err, callback)) return;
callback(err, data);
data = {text: atext.text};
callback(null, data);
})
}
//the client wants the latest text, lets return it to him
@ -158,11 +154,7 @@ exports.setText = function(padID, text, callback)
//get the pad
getPadSafe(padID, true, function(err, pad)
{
if(err)
{
callback(err);
return;
}
if(ERR(err, callback)) return;
//set the text
pad.setText(text);
@ -215,11 +207,7 @@ exports.getHTML = function(padID, rev, callback)
getPadSafe(padID, true, function(err, pad)
{
if(err)
{
callback(err);
return;
}
if(ERR(err, callback)) return;
//the client asked for a special revision
if(rev !== undefined)
@ -234,11 +222,9 @@ exports.getHTML = function(padID, rev, callback)
//get the html of this revision
exportHtml.getPadHTML(pad, rev, function(err, html)
{
if(!err)
{
data = {html: html};
}
callback(err, data);
if(ERR(err, callback)) return;
data = {html: html};
callback(null, data);
});
}
//the client wants the latest text, lets return it to him
@ -246,11 +232,11 @@ exports.getHTML = function(padID, rev, callback)
{
exportHtml.getPadHTML(pad, undefined, function (err, html)
{
if(!err)
{
data = {html: html};
}
callback(err, data);
if(ERR(err, callback)) return;
data = {html: html};
callback(null, data);
});
}
});
@ -261,11 +247,7 @@ exports.setHTML = function(padID, html, callback)
//get the pad
getPadSafe(padID, true, function(err, pad)
{
if(err)
{
callback(err);
return;
}
if(ERR(err, callback)) return;
// add a new changeset with the new html to the pad
importHtml.setPadHTML(pad, cleanText(html));
@ -293,11 +275,7 @@ exports.getRevisionsCount = function(padID, callback)
//get the pad
getPadSafe(padID, true, function(err, pad)
{
if(err)
{
callback(err);
return;
}
if(ERR(err, callback)) return;
callback(null, {revisions: pad.getHeadRevisionNumber()});
});
@ -323,7 +301,8 @@ exports.createPad = function(padID, text, callback)
//create pad
getPadSafe(padID, false, text, function(err)
{
callback(err);
if(ERR(err, callback)) return;
callback();
});
}
@ -339,11 +318,7 @@ exports.deletePad = function(padID, callback)
{
getPadSafe(padID, true, function(err, pad)
{
if(err)
{
callback(err);
return;
}
if(ERR(err, callback)) return;
pad.remove(callback);
});
@ -362,16 +337,13 @@ exports.getReadOnlyID = function(padID, callback)
//we don't need the pad object, but this function does all the security stuff for us
getPadSafe(padID, true, function(err)
{
if(err)
{
callback(err);
return;
}
if(ERR(err, callback)) return;
//get the readonlyId
readOnlyManager.getReadOnlyId(padID, function(err, readOnlyId)
{
callback(err, {readOnlyID: readOnlyId});
if(ERR(err, callback)) return;
callback(null, {readOnlyID: readOnlyId});
});
});
}
@ -396,11 +368,7 @@ exports.setPublicStatus = function(padID, publicStatus, callback)
//get the pad
getPadSafe(padID, true, function(err, pad)
{
if(err)
{
callback(err);
return;
}
if(ERR(err, callback)) return;
//convert string to boolean
if(typeof publicStatus == "string")
@ -433,11 +401,7 @@ exports.getPublicStatus = function(padID, callback)
//get the pad
getPadSafe(padID, true, function(err, pad)
{
if(err)
{
callback(err);
return;
}
if(ERR(err, callback)) return;
callback(null, {publicStatus: pad.getPublicStatus()});
});
@ -463,11 +427,7 @@ exports.setPassword = function(padID, password, callback)
//get the pad
getPadSafe(padID, true, function(err, pad)
{
if(err)
{
callback(err);
return;
}
if(ERR(err, callback)) return;
//set the password
pad.setPassword(password);
@ -496,11 +456,7 @@ exports.isPasswordProtected = function(padID, callback)
//get the pad
getPadSafe(padID, true, function(err, pad)
{
if(err)
{
callback(err);
return;
}
if(ERR(err, callback)) return;
callback(null, {isPasswordProtected: pad.isPasswordProtected()});
});
@ -542,13 +498,10 @@ function getPadSafe(padID, shouldExist, text, callback)
//check if the pad exists
padManager.doesPadExists(padID, function(err, exists)
{
//error
if(err)
{
callback(err);
}
if(ERR(err, callback)) return;
//does not exist, but should
else if(exists == false && shouldExist == true)
if(exists == false && shouldExist == true)
{
callback({stop: "padID does not exist"});
}