blob: 474c2c9ce808cf7be73f7d3ccdb73411899d3a35 [file] [log] [blame]
/*-
* ============LICENSE_START=======================================================
* OSAM Core
* ================================================================================
* Copyright (C) 2018 Netsia
* ================================================================================
* 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.
* ============LICENSE_END=========================================================
*/
package org.onap.osam.controller;
import org.onap.osam.common.exception.BadFormatException;
import org.onap.osam.common.exception.NotFoundException;
import org.onap.osam.common.exception.ServerException;
import org.onap.osam.common.exception.UnknownTypeException;
import org.slf4j.Logger;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
/**
* Created by cemturker on 30.09.2018.
*/
public abstract class AbstractController {
private Logger logger;
public AbstractController(Logger logger) {
this.logger = logger;
}
public <T> ResponseEntity<T> proceedException(Exception e) {
if (e instanceof BadFormatException || e instanceof UnknownTypeException) {
return ResponseEntity.status(HttpStatus.BAD_REQUEST).build();
} else if(e instanceof NotFoundException) {
return ResponseEntity.status(HttpStatus.NOT_FOUND).build();
} else if(e instanceof ServerException) {
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
} else {
logger.error("",e);
return ResponseEntity.status(HttpStatus.SERVICE_UNAVAILABLE).build();
}
}
}