Commit 36a09479 authored by Piotr Gawron's avatar Piotr Gawron
Browse files

error reported to the frontend is more readable

parent 43f33220
......@@ -6,9 +6,11 @@ var ConfigurationType = require('../../ConfigurationType');
var Functions = require('../../Functions');
var GuiConnector = require('../../GuiConnector');
var NetworkError = require('../../NetworkError');
var ValidationError = require('../../ValidationError');
var logger = require('../../logger');
var HttpStatus = require('http-status-codes');
var Promise = require("bluebird");
var xss = require("xss");
......@@ -253,9 +255,11 @@ ConfigurationAdminPanel.prototype.saveOption = function (type) {
value = element.val();
}
var oldVal;
GuiConnector.showProcessing();
return self.getServerConnector().getConfiguration().then(function (configuration) {
option = configuration.getOption(type);
oldVal = option.getValue();
if (option === undefined) {
return Promise.reject(new ValidationError("Unknown configuration type: " + type));
}
......@@ -317,7 +321,16 @@ ConfigurationAdminPanel.prototype.saveOption = function (type) {
}
});
}
}).catch(GuiConnector.alert).finally(GuiConnector.hideProcessing);
}).catch(function (e) {
if (e instanceof NetworkError && e.statusCode === HttpStatus.BAD_REQUEST) {
var content = e.content;
GuiConnector.alert(new ValidationError(content.reason));
option.setValue(oldVal);
element.val(oldVal);
} else {
GuiConnector.alert(e);
}
}).finally(GuiConnector.hideProcessing);
};
/**
......
......@@ -3,8 +3,9 @@ package lcsb.mapviewer.api;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.util.TreeMap;
import java.util.HashMap;
import java.util.Map;
import java.util.TreeMap;
import org.apache.log4j.Logger;
import org.springframework.http.HttpHeaders;
......@@ -37,7 +38,8 @@ public abstract class BaseController {
} else if (e instanceof ObjectExistsException) {
return createErrorResponse("Object already exists.", e.getMessage(), new HttpHeaders(), HttpStatus.CONFLICT);
} else if (e instanceof OperationNotAllowedException) {
return createErrorResponse("Operation not allowed.", e.getMessage(), new HttpHeaders(), HttpStatus.METHOD_NOT_ALLOWED);
return createErrorResponse("Operation not allowed.", e.getMessage(), new HttpHeaders(),
HttpStatus.METHOD_NOT_ALLOWED);
} else if (e instanceof QueryException) {
logger.error(e, e);
return createErrorResponse("Query server error.", e.getMessage(), new HttpHeaders(), HttpStatus.BAD_REQUEST);
......@@ -53,8 +55,10 @@ public abstract class BaseController {
private ResponseEntity<Object> createErrorResponse(String errorMessage, String error, HttpHeaders httpHeaders,
HttpStatus status) {
return new ResponseEntity<Object>(
"{\"error\" : \"" + errorMessage + "\",\"reason\":" + new Gson().toJson(error) + "}", httpHeaders, status);
Map<String, String> response = new HashMap<>();
response.put("error", errorMessage);
response.put("reason", error);
return new ResponseEntity<Object>(new Gson().toJson(response), httpHeaders, status);
}
public Map<String, Object> parseBody(String body) throws IOException, JsonParseException, JsonMappingException {
......
......@@ -293,7 +293,7 @@ public class ConfigurationRestImpl extends BaseRestImpl {
try {
configurationService.setConfigurationValue(type, value);
} catch (InvalidArgumentException e) {
throw new QueryException(e);
throw new QueryException(e.getMessage(), e);
}
return optionToMap(configurationService.getValue(type));
}
......
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