Commit 829ff89e authored by Tristan Cavelier's avatar Tristan Cavelier Committed by Sebastien Robin

Change returned error to an object.

It contains now
- status : code
- statusText : string associated with error code
- message : an explicit error message
- array : array containing some returned errors from child job(s).
parent 89c6789c
...@@ -89,7 +89,8 @@ ...@@ -89,7 +89,8 @@
// wait a little in order to simulate asynchronous operation // wait a little in order to simulate asynchronous operation
setTimeout(function () { setTimeout(function () {
that.fail('Cannot check name availability.',0); that.fail({status:0,statusText:'Unknown Error',
message:'Unknown error.'});
}, 100); }, 100);
}; // end userNameAvailable }; // end userNameAvailable
...@@ -98,7 +99,8 @@ ...@@ -98,7 +99,8 @@
// wait a little in order to simulate asynchronous saving // wait a little in order to simulate asynchronous saving
setTimeout (function () { setTimeout (function () {
that.fail('Unable to save document.',0); that.fail({status:0,statusText:'Unknown Error',
message:'Unknown error.'});
}, 100); }, 100);
}; // end saveDocument }; // end saveDocument
...@@ -110,7 +112,8 @@ ...@@ -110,7 +112,8 @@
// wait a little in order to simulate asynchronous operation // wait a little in order to simulate asynchronous operation
setTimeout(function () { setTimeout(function () {
that.fail('Unable to load document.',0); that.fail({status:0,statusText:'Unknown Error',
message:'Unknown error.'});
}, 100); }, 100);
}; // end loadDocument }; // end loadDocument
...@@ -121,7 +124,8 @@ ...@@ -121,7 +124,8 @@
// 'lastModified':date,'creationDate':date} // 'lastModified':date,'creationDate':date}
setTimeout(function () { setTimeout(function () {
that.fail('Cannot get document list.',0); that.fail({status:0,statusText:'Unknown Error',
message:'Unknown error.'});
}, 100); }, 100);
}; // end getDocumentList }; // end getDocumentList
...@@ -132,7 +136,8 @@ ...@@ -132,7 +136,8 @@
// in the jobendcallback arguments. // in the jobendcallback arguments.
setTimeout (function () { setTimeout (function () {
that.fail('Unable to remove anything.',0); that.fail({status:0,statusText:'Unknown Error',
message:'Unknown error.'});
}, 100); }, 100);
}; };
return that; return that;
...@@ -171,7 +176,9 @@ ...@@ -171,7 +176,9 @@
// wait a little in order to simulate asynchronous operation // wait a little in order to simulate asynchronous operation
setTimeout(function () { setTimeout(function () {
that.fail('Document not found.',404); that.fail({status:404,statusText:'Not Found',
message:'Document "'+ that.getFileName() +
'" not found.'});
}, 100); }, 100);
}; // end loadDocument }; // end loadDocument
...@@ -182,7 +189,8 @@ ...@@ -182,7 +189,8 @@
// 'lastModified':date,'creationDate':date} // 'lastModified':date,'creationDate':date}
setTimeout(function () { setTimeout(function () {
that.fail('User collection not found.',404); that.fail({status:404,statusText:'Not Found',
message:'User list not found.'});
}, 100); }, 100);
}; // end getDocumentList }; // end getDocumentList
...@@ -217,10 +225,10 @@ ...@@ -217,10 +225,10 @@
return that.done(ifokreturn); return that.done(ifokreturn);
} }
if ( tries < 3 ) { if ( tries < 3 ) {
return that.fail('' + (3 - tries) + ' tries left.'); return that.fail({message:'' + (3 - tries) + ' tries left.'});
} }
if ( tries > 3 ) { if ( tries > 3 ) {
return that.fail('Too much tries.'); return that.fail({message:'Too much tries.'});
} }
}; };
......
...@@ -832,18 +832,27 @@ var JIO = ...@@ -832,18 +832,27 @@ var JIO =
priv.res.status = 'fail'; priv.res.status = 'fail';
priv.res.message = 'Job Stopped!'; priv.res.message = 'Job Stopped!';
priv.res.errno = 0; priv.res.error = {};
priv.res.error.status = 0;
priv.res.error.statusText = 'Replaced';
priv.res.error.message = 'The job was replaced by a newer one.';
priv['fail_'+priv.job.method](); priv['fail_'+priv.job.method]();
priv.callback(priv.res); priv.callback(priv.res);
}; };
that.fail = function ( message, errno ) { that.fail = function ( errorobject ) {
// Called when a job has failed. // Called when a job has failed.
// It will retry the job from a certain moment or it will return // It will retry the job from a certain moment or it will return
// a failure. // a failure.
priv.res.status = 'fail'; priv.res.status = 'fail';
priv.res.message = message; priv.res.error = errorobject;
priv.res.errno = errno; // init error object with default values
priv.res.error.status = priv.res.error.status || 0;
priv.res.error.statusText =
priv.res.error.statusText || 'Unknown Error';
priv.res.error.array = priv.res.error.array || [];
priv.res.error.message = priv.res.error.message || '';
// retry ?
if (!priv.job.maxtries || if (!priv.job.maxtries ||
priv.job.tries < priv.job.maxtries) { priv.job.tries < priv.job.maxtries) {
priv.retryLater(); priv.retryLater();
......
...@@ -113,7 +113,9 @@ var jio_storage_loader = function ( LocalOrCookieStorage, Base64, Jio, $) { ...@@ -113,7 +113,9 @@ var jio_storage_loader = function ( LocalOrCookieStorage, Base64, Jio, $) {
'jio/local/'+that.getStorageUserName()+'/'+ 'jio/local/'+that.getStorageUserName()+'/'+
that.getApplicantID()+'/'+that.getFileName()); that.getApplicantID()+'/'+that.getFileName());
if (!doc) { if (!doc) {
that.fail('Document not found.',404); that.fail({status:404,statusText:'Not Found.',
message:'Document "'+ that.getFileName() +
'" not found in localStorage.'});
} else { } else {
if (!settings.getContent) { if (!settings.getContent) {
delete doc.fileContent; delete doc.fileContent;
...@@ -269,8 +271,9 @@ var jio_storage_loader = function ( LocalOrCookieStorage, Base64, Jio, $) { ...@@ -269,8 +271,9 @@ var jio_storage_loader = function ( LocalOrCookieStorage, Base64, Jio, $) {
if (type.status === 404) { if (type.status === 404) {
that.done(true); that.done(true);
} else { } else {
that.fail('Cannot check if ' + that.getUserName() + type.message = 'Cannot check availability of "' +
' is available.',type.status); that.getUserName() + '" into DAVStorage.';
that.fail(type);
} }
} }
} ); } );
...@@ -303,7 +306,9 @@ var jio_storage_loader = function ( LocalOrCookieStorage, Base64, Jio, $) { ...@@ -303,7 +306,9 @@ var jio_storage_loader = function ( LocalOrCookieStorage, Base64, Jio, $) {
that.done(); that.done();
}, },
error: function (type) { error: function (type) {
that.fail('Cannot save document.',type.status); type.message = 'Cannot save "' + that.getFileName() +
'" into DAVStorage.';
that.fail(type);
} }
} ); } );
//// end saving on dav //// end saving on dav
...@@ -344,13 +349,16 @@ var jio_storage_loader = function ( LocalOrCookieStorage, Base64, Jio, $) { ...@@ -344,13 +349,16 @@ var jio_storage_loader = function ( LocalOrCookieStorage, Base64, Jio, $) {
that.done(doc); that.done(doc);
}, },
error: function (type) { error: function (type) {
var message;
if (type.status === 404) { if (type.status === 404) {
message = 'Document not found.'; type.message = 'Document "' +
that.getFileName() +
'" not found in localStorage.';
} else { } else {
message = 'Cannot load "'+that.getFileName()+'".'; type.message =
'Cannot load "' + that.getFileName() +
'" from DAVStorage.';
} }
that.fail(message,type.status); that.fail(type);
} }
} ); } );
}; };
...@@ -386,7 +394,9 @@ var jio_storage_loader = function ( LocalOrCookieStorage, Base64, Jio, $) { ...@@ -386,7 +394,9 @@ var jio_storage_loader = function ( LocalOrCookieStorage, Base64, Jio, $) {
} }
}, },
error: function (type) { error: function (type) {
that.fail('Cannot get document informations.',type.status); type.message = 'Cannot load "' + that.getFileName() +
'" informations from DAVStorage.';
that.fail(type);
} }
} ); } );
}; };
...@@ -446,7 +456,9 @@ var jio_storage_loader = function ( LocalOrCookieStorage, Base64, Jio, $) { ...@@ -446,7 +456,9 @@ var jio_storage_loader = function ( LocalOrCookieStorage, Base64, Jio, $) {
that.done(documentArrayList); that.done(documentArrayList);
}, },
error: function (type) { error: function (type) {
that.fail('Cannot get list.',type.status); type.message =
'Cannot get a document list from DAVStorage.';
that.fail(type);
} }
} ); } );
}; };
...@@ -478,8 +490,9 @@ var jio_storage_loader = function ( LocalOrCookieStorage, Base64, Jio, $) { ...@@ -478,8 +490,9 @@ var jio_storage_loader = function ( LocalOrCookieStorage, Base64, Jio, $) {
if (type.status === 404) { if (type.status === 404) {
that.done(); that.done();
} else { } else {
that.fail('Cannot remove "' + that.getFileName() + type.message = 'Cannot remove "' + that.getFileName() +
'".',type.status); '" from DAVStorage.';
that.fail(type);
} }
} }
} ); } );
...@@ -519,12 +532,13 @@ var jio_storage_loader = function ( LocalOrCookieStorage, Base64, Jio, $) { ...@@ -519,12 +532,13 @@ var jio_storage_loader = function ( LocalOrCookieStorage, Base64, Jio, $) {
// this.job.userName: the name we want to check. // this.job.userName: the name we want to check.
// this.job.storage.storageArray: An Array of storages. // this.job.storage.storageArray: An Array of storages.
var newjob = {}, i = 'id', done = false, var newjob = {}, i = 'id', done = false, errorArray = [],
res = {'status':'done'}, callback = function (result) { res = {'status':'done'}, callback = function (result) {
priv.returnsValuesArray.push(result); priv.returnsValuesArray.push(result);
if (!done) { if (!done) {
if (result.status === 'fail') { if (result.status === 'fail') {
res.status = 'fail'; res.status = 'fail';
errorArray.push(result.error);
} else { } else {
if (result.return_value === false) { if (result.return_value === false) {
that.done (false); that.done (false);
...@@ -535,7 +549,12 @@ var jio_storage_loader = function ( LocalOrCookieStorage, Base64, Jio, $) { ...@@ -535,7 +549,12 @@ var jio_storage_loader = function ( LocalOrCookieStorage, Base64, Jio, $) {
if (priv.returnsValuesArray.length === if (priv.returnsValuesArray.length ===
priv.length) { priv.length) {
if (res.status === 'fail') { if (res.status === 'fail') {
that.fail ('Unable to check name availability.',0); that.fail (
{status:207,
statusText:'Multi-Status',
message:'Some check availability of "' +
that.getUserName() + '" requests have failed.',
array:errorArray});
} else { } else {
that.done (true); that.done (true);
} }
...@@ -556,7 +575,8 @@ var jio_storage_loader = function ( LocalOrCookieStorage, Base64, Jio, $) { ...@@ -556,7 +575,8 @@ var jio_storage_loader = function ( LocalOrCookieStorage, Base64, Jio, $) {
// this.job.fileName: the document name. // this.job.fileName: the document name.
// this.job.fileContent: the document content. // this.job.fileContent: the document content.
var newjob = {}, res = {'status':'done'}, i = 'id', done = false, var newjob = {}, res = {'status':'done'}, i = 'id',
done = false, errorArray = [],
callback = function (result) { callback = function (result) {
priv.returnsValuesArray.push(result); priv.returnsValuesArray.push(result);
if (!done) { if (!done) {
...@@ -564,9 +584,15 @@ var jio_storage_loader = function ( LocalOrCookieStorage, Base64, Jio, $) { ...@@ -564,9 +584,15 @@ var jio_storage_loader = function ( LocalOrCookieStorage, Base64, Jio, $) {
that.done (); that.done ();
done = true; done = true;
} else { } else {
errorArray.push(result.error);
if (priv.returnsValuesArray.length === if (priv.returnsValuesArray.length ===
priv.length) { priv.length) {
that.fail ('Unable to save any file.',0); that.fail (
{status:207,
statusText:'Multi-Status',
message:'All save "' + that.getFileName() +
'" requests have failed.',
array:errorArray});
} }
} }
} }
...@@ -586,11 +612,8 @@ var jio_storage_loader = function ( LocalOrCookieStorage, Base64, Jio, $) { ...@@ -586,11 +612,8 @@ var jio_storage_loader = function ( LocalOrCookieStorage, Base64, Jio, $) {
// this.job.storage.password: the user password. // this.job.storage.password: the user password.
// this.job.options.getContent: if true, also get the file content. // this.job.options.getContent: if true, also get the file content.
// document object is {'fileName':string,'fileContent':string,
// 'creationDate':date,'lastModified':date}
var newjob = {}, aredifferent = false, doc = {}, i = 'id', var newjob = {}, aredifferent = false, doc = {}, i = 'id',
done = false, done = false, errorArray = [],
res = {'status':'done'}, callback = function (result) { res = {'status':'done'}, callback = function (result) {
priv.returnsValuesArray.push(result); priv.returnsValuesArray.push(result);
if (!done) { if (!done) {
...@@ -598,9 +621,15 @@ var jio_storage_loader = function ( LocalOrCookieStorage, Base64, Jio, $) { ...@@ -598,9 +621,15 @@ var jio_storage_loader = function ( LocalOrCookieStorage, Base64, Jio, $) {
that.done (result.return_value); that.done (result.return_value);
done = true; done = true;
} else { } else {
errorArray.push(result.error);
if (priv.returnsValuesArray.length === if (priv.returnsValuesArray.length ===
priv.length) { priv.length) {
that.fail ('Unable to load any file.',0); that.fail (
{status:207,
statusText:'Multi-Status',
message:'All load "' + that.getFileName() +
'" requests have failed.',
array:errorArray});
} }
} }
} }
...@@ -617,10 +646,8 @@ var jio_storage_loader = function ( LocalOrCookieStorage, Base64, Jio, $) { ...@@ -617,10 +646,8 @@ var jio_storage_loader = function ( LocalOrCookieStorage, Base64, Jio, $) {
// this.job.storage.password: the user password. // this.job.storage.password: the user password.
// this.job.applicant.ID: the applicant id. // this.job.applicant.ID: the applicant id.
// the list is [object,object,...] -> object = {'fileName':string, var newjob = {}, res = {'status':'done'}, i = 'id',
// 'lastModified':date,'creationDate':date} done = false, errorArray = [],
var newjob = {}, res = {'status':'done'}, i = 'id', done = false,
callback = function (result) { callback = function (result) {
priv.returnsValuesArray.push(result); priv.returnsValuesArray.push(result);
if (!done) { if (!done) {
...@@ -628,9 +655,15 @@ var jio_storage_loader = function ( LocalOrCookieStorage, Base64, Jio, $) { ...@@ -628,9 +655,15 @@ var jio_storage_loader = function ( LocalOrCookieStorage, Base64, Jio, $) {
that.done (result.return_value); that.done (result.return_value);
done = true; done = true;
} else { } else {
errorArray.push(result.error);
if (priv.returnsValuesArray.length === if (priv.returnsValuesArray.length ===
priv.length) { priv.length) {
that.fail ('Unable to retrieve list.',0); that.fail (
{status:207,
statusText:'Multi-Status',
message:'All get document list requests'+
' have failed',
array:errorArray});
} }
} }
} }
...@@ -647,7 +680,8 @@ var jio_storage_loader = function ( LocalOrCookieStorage, Base64, Jio, $) { ...@@ -647,7 +680,8 @@ var jio_storage_loader = function ( LocalOrCookieStorage, Base64, Jio, $) {
// this.job.storage.password: the user password. // this.job.storage.password: the user password.
// this.job.applicant.ID: the applicant id. // this.job.applicant.ID: the applicant id.
var newjob = {}, res = {'status':'done'}, i = 'key', done = false, var newjob = {}, res = {'status':'done'}, i = 'key',
done = false, errorArray = [],
callback = function (result) { callback = function (result) {
priv.returnsValuesArray.push(result); priv.returnsValuesArray.push(result);
if (!done) { if (!done) {
...@@ -655,9 +689,15 @@ var jio_storage_loader = function ( LocalOrCookieStorage, Base64, Jio, $) { ...@@ -655,9 +689,15 @@ var jio_storage_loader = function ( LocalOrCookieStorage, Base64, Jio, $) {
that.done (); that.done ();
done = true; done = true;
} else { } else {
errorArray.push(result.error);
if (priv.returnsValuesArray.length === if (priv.returnsValuesArray.length ===
priv.length) { priv.length) {
that.fail ('Unable to remove any file.',0); that.fail (
{status:207,
statusText:'Multi-Status',
message:'All remove "' + that.getFileName() +
'" requests have failed.',
array:errorArray});
} }
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment