Skip to content

Commit

Permalink
updated some model naming
Browse files Browse the repository at this point in the history
  • Loading branch information
supernomad committed Jun 21, 2015
1 parent d416ac5 commit c73f574
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 24 deletions.
4 changes: 2 additions & 2 deletions libs/models/errorModels.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ function GenericError(code, error, message) {
self.Message = message;
}

function missingCacheItem() {
function uploadMissing() {
return new GenericError(404, "Missing Upload Error", "The upload specified could not be found, please check the supplied id and try again.");
}

Expand All @@ -19,7 +19,7 @@ function validationError(msg) {

module.exports = {
GenericError: GenericError,
MissingCacheItem: missingCacheItem,
UploadMissing: uploadMissing,
ServerError: serverError,
ValidationError: validationError
};
10 changes: 5 additions & 5 deletions libs/validators/chunked-upload-validators.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,23 @@ var valid = "valid";
function validateUploadRequest(uploadRequest, maxSize) {
if(!typeHelper.isObject(uploadRequest)) {
return "Upload request object was not recieved.";
} else if (!uploadRequest.hasOwnProperty('fileName') || !typeHelper.isString(uploadRequest.fileName)) {
} else if (!typeHelper.isString(uploadRequest.fileName)) {
return "Upload fileName missing.";
} else if (!uploadRequest.hasOwnProperty('fileSize') || !typeHelper.isNumber(uploadRequest.fileSize)) {
} else if (!typeHelper.isNumber(uploadRequest.fileSize)) {
return "Upload fileSize missing.";
} else if (uploadRequest.fileSize <= 0) {
return "Upload fileSize must be greater than 0 bytes.";
} else if (maxSize > 0 && uploadRequest.fileSize > maxSize) {
return "Upload fileSize is greater than the maximum size of " + maxSize + " bytes.";
} else if (!uploadRequest.hasOwnProperty('chunkSize') || !typeHelper.isNumber(uploadRequest.chunkSize)) {
} else if (!typeHelper.isNumber(uploadRequest.chunkSize)) {
return "Upload chunkSize missing.";
} else if (uploadRequest.chunkSize <= 0) {
return "Upload chunkSize must be greater than 0 bytes.";
} else if (!uploadRequest.hasOwnProperty('count') || !typeHelper.isNumber(uploadRequest.count)) {
} else if (!typeHelper.isNumber(uploadRequest.count)) {
return "Upload count missing.";
} else if (uploadRequest.count !== (uploadRequest.fileSize / uploadRequest.chunkSize | 0) + (uploadRequest.fileSize % uploadRequest.chunkSize > 0 ? 1 : 0)) {
return "Upload count does not match computed value, check upload file size and chunkSize.";
} else if (!uploadRequest.hasOwnProperty('destination') || !typeHelper.isString(uploadRequest.destination)) {
} else if (!typeHelper.isString(uploadRequest.destination)) {
return "Upload destination missing.";
} else {
return valid;
Expand Down
26 changes: 13 additions & 13 deletions routes/chunked-upload-routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ var routes = {
if(typeHelper.doesExist(upload.value)){
res.json(new apiModels.ApiResponse(routePrefix, {}, upload.value));
} else {
throw errorModels.MissingCacheItem();
throw errorModels.UploadMissing();
}
});
}),
Expand Down Expand Up @@ -112,7 +112,7 @@ var routes = {
}
});
} else {
throw errorModels.MissingCacheItem();
throw errorModels.UploadMissing();
}
});
}),
Expand All @@ -136,24 +136,24 @@ var routes = {
});
}),
"error": new apiModels.ErrorHandler(function (error, req, res, next) {
if(error instanceof errorModels.GenericError) {
res.status(error.Code);
res.json({
Error: error.Error,
Message: error.Message
});
} else {
next();
}
if(error instanceof errorModels.GenericError) {
res.status(error.Code);
res.json({
Error: error.Error,
Message: error.Message
});
} else {
next();
}
})
};

function configure(cache, storage, options) {
if(typeHelper.isObject(options)) {
if(options.hasOwnProperty('debug') && typeHelper.isBoolean(options.debug)){
if(typeHelper.isBoolean(options.debug)){
debug = options.debug;
}
if(options.hasOwnProperty('routePrefix') && typeHelper.isString(options.routePrefix)){
if(typeHelper.isString(options.routePrefix)){
routePrefix = stringHelper.stripTrailingSlashes(options.routePrefix);
}
}
Expand Down
8 changes: 4 additions & 4 deletions test/routes/chunked-upload-routes-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ describe("chunked-upload-routes.js", function() {
}).should.throw(errorModels.GenericError);;
});

it('should throw a MissingCacheItem error if the supplied uploadId does not exist', function() {
it('should throw a UploadMissing error if the supplied uploadId does not exist', function() {
(function() {
routes.get.handler({
params: {
Expand Down Expand Up @@ -261,7 +261,7 @@ describe("chunked-upload-routes.js", function() {
}).should.throw(errorModels.GenericError);;
});

it('should throw a MissingCacheItem error if the supplied uploadId does not exist', function() {
it('should throw a UploadMissing error if the supplied uploadId does not exist', function() {
(function() {
routes.put.handler({
params: {
Expand Down Expand Up @@ -321,7 +321,7 @@ describe("chunked-upload-routes.js", function() {
}).should.throw(errorModels.GenericError);;
});

it('should throw a MissingCacheItem error if the supplied uploadId does not exist', function() {
it('should throw a UploadMissing error if the supplied uploadId does not exist', function() {
(function() {
routes.delete.handler({
params: {
Expand All @@ -344,7 +344,7 @@ describe("chunked-upload-routes.js", function() {
});

it('should handle any custom errors', function(done) {
routes.error.handler(errorModels.MissingCacheItem(), null, {
routes.error.handler(errorModels.UploadMissing(), null, {
status: function(status) {
should.exist(status);
status.should.be.a.Number;
Expand Down

0 comments on commit c73f574

Please sign in to comment.