Commit 0fce3ce9 authored by Tristan Cavelier's avatar Tristan Cavelier

erp5storage.js improve error management

parent e37bf29c
...@@ -10,7 +10,8 @@ ...@@ -10,7 +10,8 @@
// } // }
/*jslint indent: 2, nomen: true, unparam: true */ /*jslint indent: 2, nomen: true, unparam: true */
/*global jIO, complex_queries, console, UriTemplate, FormData, RSVP */ /*global jIO, complex_queries, console, UriTemplate, FormData, RSVP,
ProgressEvent */
(function (jIO, complex_queries) { (function (jIO, complex_queries) {
"use strict"; "use strict";
...@@ -62,14 +63,17 @@ ...@@ -62,14 +63,17 @@
.then(function (response) { .then(function (response) {
command.success({"data": response}); command.success({"data": response});
}) })
.fail(function (error) { .fail(function (event) {
console.error(error); console.error(event);
if (event instanceof ProgressEvent) {
command.error(
event.target.status,
event.target.statusText,
"Cannot find document"
);
}
// XXX How to propagate the error // XXX How to propagate the error
command.error( command.error(event);
"not_found",
"missing",
"Cannot find document"
);
}); });
}; };
...@@ -115,13 +119,16 @@ ...@@ -115,13 +119,16 @@
"Cannot find document" "Cannot find document"
); );
} }
}, function (error) { }, function (event) {
console.error(error); console.error(event);
command.error( if (event instanceof ProgressEvent) {
500, return command.error(
"Too bad...", event.target.status,
"Unable to post doc" event.target.statusText,
); "Unable to post doc"
);
}
command.error(event);
}); });
}; };
...@@ -158,13 +165,16 @@ ...@@ -158,13 +165,16 @@
.then(function (result) { .then(function (result) {
command.success(result); command.success(result);
}) })
.fail(function (error) { .fail(function (event) {
console.error(error); console.error(event);
command.error( if (event instanceof ProgressEvent) {
"error", return command.error(
"did not work as expected", event.target.status,
"Unable to call put" event.target.statusText,
); "Unable to call put"
);
}
command.error(event);
}); });
}; };
...@@ -223,13 +233,16 @@ ...@@ -223,13 +233,16 @@
count = result.length; count = result.length;
command.success({"data": {"rows": result, "total_rows": count}}); command.success({"data": {"rows": result, "total_rows": count}});
}) })
.fail(function (error) { .fail(function (event) {
console.error(error); console.error(event);
command.error( if (event instanceof ProgressEvent) {
"error", return command.error(
"did not work as expected", event.target.status,
"Unable to call allDocs" event.target.statusText,
); "Cannot get list of document"
);
}
command.error(event);
}); });
}; };
......
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