Commit 11279155 authored by Noel Alonso's avatar Noel Alonso
Browse files

Añade handler para excepciones de tipo forbidden

parent 75a78e50
Loading
Loading
Loading
Loading
+44 −0
Original line number Diff line number Diff line
package es.redmic.restlib.exceptionhandler;

/*-
 * #%L
 * rest-lib
 * %%
 * Copyright (C) 2019 REDMIC Project / Server
 * %%
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * 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.
 * #L%
 */

import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestController;

import es.redmic.exception.common.BadRequestException;
import es.redmic.exception.common.RequestForbiddenException;
import es.redmic.exception.dto.ErrorDTO;
import es.redmic.exception.handler.BaseExceptionHandler;

@ControllerAdvice(annotations = RestController.class)
public class RequestForbiddenExceptionHandler extends BaseExceptionHandler {

	@ExceptionHandler(value = RequestForbiddenException.class)
	@ResponseStatus(value = HttpStatus.FORBIDDEN) // 403
	@ResponseBody
	public ErrorDTO handleBadRequestException(BadRequestException e) {
		return getError(e);
	}
}