2012-04-07 17:45:35 +02:00
|
|
|
/*
|
|
|
|
* Copyright [2011] [wisemapping]
|
|
|
|
*
|
|
|
|
* Licensed under WiseMapping Public License, Version 1.0 (the "License").
|
|
|
|
* It is basically the Apache License, Version 2.0 (the "License") plus the
|
|
|
|
* "powered by wisemapping" text requirement on every single page;
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the license at
|
|
|
|
*
|
|
|
|
* http://www.wisemapping.org/license
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
2012-02-22 00:04:17 +01:00
|
|
|
|
2012-04-07 17:45:35 +02:00
|
|
|
package com.wisemapping.rest;
|
2012-02-22 00:04:17 +01:00
|
|
|
|
2012-04-07 17:45:35 +02:00
|
|
|
import com.wisemapping.rest.model.RestErrors;
|
2012-02-25 15:56:20 +01:00
|
|
|
import org.jetbrains.annotations.NotNull;
|
2012-04-07 17:45:35 +02:00
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
import org.springframework.context.support.ResourceBundleMessageSource;
|
2012-02-22 00:04:17 +01:00
|
|
|
import org.springframework.http.HttpStatus;
|
|
|
|
import org.springframework.web.bind.annotation.ExceptionHandler;
|
|
|
|
import org.springframework.web.bind.annotation.ResponseBody;
|
|
|
|
import org.springframework.web.bind.annotation.ResponseStatus;
|
|
|
|
|
|
|
|
public class BaseController {
|
|
|
|
|
2012-04-07 17:45:35 +02:00
|
|
|
@Autowired
|
|
|
|
private ResourceBundleMessageSource messageSource;
|
|
|
|
|
2012-02-22 00:04:17 +01:00
|
|
|
@ExceptionHandler(IllegalArgumentException.class)
|
|
|
|
@ResponseStatus(HttpStatus.BAD_REQUEST)
|
|
|
|
@ResponseBody
|
2012-06-08 00:45:22 +02:00
|
|
|
public RestErrors handleClientErrors(@NotNull IllegalArgumentException ex) {
|
|
|
|
return new RestErrors(ex.getMessage());
|
2012-02-22 00:04:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@ExceptionHandler(Exception.class)
|
|
|
|
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
|
|
|
|
@ResponseBody
|
2012-02-25 15:56:20 +01:00
|
|
|
public String handleServerErrors(@NotNull Exception ex) {
|
2012-02-22 00:04:17 +01:00
|
|
|
ex.printStackTrace();
|
|
|
|
return ex.getMessage();
|
|
|
|
}
|
2012-04-07 17:45:35 +02:00
|
|
|
|
|
|
|
@ExceptionHandler(ValidationException.class)
|
|
|
|
@ResponseStatus(HttpStatus.BAD_REQUEST)
|
|
|
|
public RestErrors handleValidationErrors(@NotNull ValidationException ex) {
|
|
|
|
return new RestErrors(ex.getErrors(),messageSource);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-02-22 00:04:17 +01:00
|
|
|
}
|