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 @@
// wait a little in order to simulate asynchronous operation
setTimeout(function () {
that.fail('Cannot check name availability.',0);
that.fail({status:0,statusText:'Unknown Error',
message:'Unknown error.'});
}, 100);
}; // end userNameAvailable
......@@ -98,7 +99,8 @@
// wait a little in order to simulate asynchronous saving
setTimeout (function () {
that.fail('Unable to save document.',0);
that.fail({status:0,statusText:'Unknown Error',
message:'Unknown error.'});
}, 100);
}; // end saveDocument
......@@ -110,7 +112,8 @@
// wait a little in order to simulate asynchronous operation
setTimeout(function () {
that.fail('Unable to load document.',0);
that.fail({status:0,statusText:'Unknown Error',
message:'Unknown error.'});
}, 100);
}; // end loadDocument
......@@ -121,7 +124,8 @@
// 'lastModified':date,'creationDate':date}
setTimeout(function () {
that.fail('Cannot get document list.',0);
that.fail({status:0,statusText:'Unknown Error',
message:'Unknown error.'});
}, 100);
}; // end getDocumentList
......@@ -132,7 +136,8 @@
// in the jobendcallback arguments.
setTimeout (function () {
that.fail('Unable to remove anything.',0);
that.fail({status:0,statusText:'Unknown Error',
message:'Unknown error.'});
}, 100);
};
return that;
......@@ -171,7 +176,9 @@
// wait a little in order to simulate asynchronous operation
setTimeout(function () {
that.fail('Document not found.',404);
that.fail({status:404,statusText:'Not Found',
message:'Document "'+ that.getFileName() +
'" not found.'});
}, 100);
}; // end loadDocument
......@@ -182,7 +189,8 @@
// 'lastModified':date,'creationDate':date}
setTimeout(function () {
that.fail('User collection not found.',404);
that.fail({status:404,statusText:'Not Found',
message:'User list not found.'});
}, 100);
}; // end getDocumentList
......@@ -217,10 +225,10 @@
return that.done(ifokreturn);
}
if ( tries < 3 ) {
return that.fail('' + (3 - tries) + ' tries left.');
return that.fail({message:'' + (3 - tries) + ' tries left.'});
}
if ( tries > 3 ) {
return that.fail('Too much tries.');
return that.fail({message:'Too much tries.'});
}
};
......
......@@ -832,18 +832,27 @@ var JIO =
priv.res.status = 'fail';
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.callback(priv.res);
};
that.fail = function ( message, errno ) {
that.fail = function ( errorobject ) {
// Called when a job has failed.
// It will retry the job from a certain moment or it will return
// a failure.
priv.res.status = 'fail';
priv.res.message = message;
priv.res.errno = errno;
priv.res.error = errorobject;
// 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 ||
priv.job.tries < priv.job.maxtries) {
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