Added VNFM Simulator project
[so.git] / vnfm-simulator / vnf-service / src / main / java / org / onap / svnfm / simulator / exception / GlobalExceptionHandler.java
1 package org.onap.svnfm.simulator.exception;
2
3 import org.springframework.http.HttpHeaders;
4 import org.springframework.http.HttpStatus;
5 import org.springframework.http.ResponseEntity;
6 import org.springframework.http.converter.HttpMessageNotReadableException;
7 import org.springframework.web.HttpMediaTypeNotSupportedException;
8 import org.springframework.web.bind.annotation.ControllerAdvice;
9 import org.springframework.web.context.request.WebRequest;
10 import org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler;
11
12 @ControllerAdvice
13 public class GlobalExceptionHandler extends ResponseEntityExceptionHandler {
14         @Override
15         protected ResponseEntity<Object> handleHttpMessageNotReadable(HttpMessageNotReadableException ex,
16                         HttpHeaders headers, HttpStatus status, WebRequest request) {
17                 String error = "Malformed JSON request";
18                 return new ResponseEntity<>(error, HttpStatus.BAD_REQUEST);
19         }
20
21         @Override
22         protected ResponseEntity<Object> handleHttpMediaTypeNotSupported(HttpMediaTypeNotSupportedException ex,
23                         HttpHeaders headers, HttpStatus status, WebRequest request) {
24                 String error = "Media type Not Supported";
25                 return new ResponseEntity<>(error, HttpStatus.UNSUPPORTED_MEDIA_TYPE);
26         }
27 }