Search in sources :

Example 1 with Status

use of io.seldon.protos.PredictionProtos.Status in project seldon-core by SeldonIO.

the class ExceptionControllerAdvice method handleUnauthorizedException.

@ExceptionHandler(APIException.class)
public ResponseEntity<String> handleUnauthorizedException(APIException exception) throws InvalidProtocolBufferException {
    Status.Builder statusBuilder = Status.newBuilder();
    statusBuilder.setCode(exception.getApiExceptionType().getId());
    statusBuilder.setReason(exception.getApiExceptionType().getMessage());
    statusBuilder.setInfo(exception.getInfo());
    statusBuilder.setStatus(Status.StatusFlag.FAILURE);
    Status status = statusBuilder.build();
    String json;
    json = ProtoBufUtils.toJson(status);
    return new ResponseEntity<String>(json, HttpStatus.valueOf(exception.getApiExceptionType().getHttpCode()));
}
Also used : HttpStatus(org.springframework.http.HttpStatus) Status(io.seldon.protos.PredictionProtos.Status) ResponseEntity(org.springframework.http.ResponseEntity) ExceptionHandler(org.springframework.web.bind.annotation.ExceptionHandler)

Example 2 with Status

use of io.seldon.protos.PredictionProtos.Status in project seldon-core by SeldonIO.

the class ExceptionControllerAdvice method handleUnauthorizedException.

@ExceptionHandler(SeldonAPIException.class)
public ResponseEntity<String> handleUnauthorizedException(SeldonAPIException exception) throws InvalidProtocolBufferException {
    Status.Builder statusBuilder = Status.newBuilder();
    statusBuilder.setCode(exception.getApiExceptionType().getId());
    statusBuilder.setReason(exception.getApiExceptionType().getMessage());
    statusBuilder.setInfo(exception.getInfo());
    statusBuilder.setStatus(Status.StatusFlag.FAILURE);
    Status status = statusBuilder.build();
    String json;
    json = ProtoBufUtils.toJson(status);
    return new ResponseEntity<String>(json, HttpStatus.valueOf(exception.getApiExceptionType().getHttpCode()));
}
Also used : HttpStatus(org.springframework.http.HttpStatus) Status(io.seldon.protos.PredictionProtos.Status) ResponseEntity(org.springframework.http.ResponseEntity) ExceptionHandler(org.springframework.web.bind.annotation.ExceptionHandler)

Aggregations

Status (io.seldon.protos.PredictionProtos.Status)2 HttpStatus (org.springframework.http.HttpStatus)2 ResponseEntity (org.springframework.http.ResponseEntity)2 ExceptionHandler (org.springframework.web.bind.annotation.ExceptionHandler)2