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();
......
This diff is collapsed.
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