package org.bench4q.master.exception;

import org.bench4q.share.models.ErrorResponseModel;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus;

@Component
public class Bench4QExceptionSweeper {
	@ExceptionHandler(Bench4QException.class)
	@ResponseStatus(value = HttpStatus.BAD_REQUEST)
	@ResponseBody
	public ErrorResponseModel handleException(Bench4QException e) {
		return ErrorResponseModel.buildErrorResponse(e.getCode(),
				e.getMessage(), e.getResource());
	}
}
