Commit f6e1660d authored by Piotr Gawron's avatar Piotr Gawron
Browse files

instead of raising exception promise is rejected with proper error

parent 1699a94f
......@@ -122,16 +122,14 @@ CustomMap.prototype.init = function () {
return Promise.each(ids, function (overlayId) {
try {
return self.openDataOverlay(overlayId);
} catch (e) {
return self.openDataOverlay(overlayId).catch(function (e) {
if (e instanceof SecurityError) {
logger.debug(e.message);
sessionData.setSelectedBackgroundOverlay(self.getProject().getDataOverlays()[0].getId());
} else {
return Promise.reject(e);
}
}
});
});
}).then(function () {
var logo2 = self.getControl(ControlType.LOGO_2_IMG);
......@@ -224,7 +222,7 @@ CustomMap.prototype.openDataOverlay = function (param) {
identifier = parseInt(identifier);
if (isNaN(identifier)) {
throw new Error("invalid id: " + param);
return Promise.reject(new Error("invalid id: " + param));
}
var overlayToOpen = null;
......@@ -237,7 +235,7 @@ CustomMap.prototype.openDataOverlay = function (param) {
}
if (overlayToOpen === null) {
throw new SecurityError("You have no privileges for selected overlay");
return Promise.reject(new SecurityError("You have no privileges for selected overlay"));
} else {
return overlayToOpen.init().then(function () {
if (overlayToOpen.getInputDataAvailable()) {
......
......@@ -70,12 +70,11 @@ describe('CustomMap', function () {
describe("openDataOverlay", function () {
it("for not existing id", function () {
var map = helper.createCustomMap();
try {
map.openDataOverlay(-1);
return map.openDataOverlay(-1).then(function () {
assert.ok(false);
} catch (exception) {
}).catch(function (exception) {
assert.ok(exception.message.indexOf("You have no privileges") >= 0);
}
});
});
it("for int id", function () {
......
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