All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.yahoo.bard.webservice.exception.FiliDataExceptionHandler Maven / Gradle / Ivy

Go to download

Fili web service library provides core capabilities for RESTful aggregation navigation, query planning and metadata

There is a newer version: 1.1.13
Show newest version
// Copyright 2018 Oath Inc.
// Licensed under the terms of the Apache license. Please see LICENSE.md file distributed with this work for terms.
package com.yahoo.bard.webservice.exception;

import static javax.ws.rs.core.Response.Status.BAD_REQUEST;
import static javax.ws.rs.core.Response.Status.GATEWAY_TIMEOUT;
import static javax.ws.rs.core.Response.Status.INTERNAL_SERVER_ERROR;

import com.yahoo.bard.webservice.data.dimension.TimeoutException;
import com.yahoo.bard.webservice.table.resolver.NoMatchFoundException;
import com.yahoo.bard.webservice.web.RequestValidationException;
import com.yahoo.bard.webservice.web.apirequest.DataApiRequest;
import com.yahoo.bard.webservice.web.handlers.RequestHandlerUtils;

import com.fasterxml.jackson.databind.ObjectWriter;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Optional;

import javax.ws.rs.container.AsyncResponse;
import javax.ws.rs.container.ContainerRequestContext;

/**
 * The default implementation of {@link DataExceptionHandler}.
 * 

* This class handles the following cases: *

    *
  1. RequestValidationException - builds an error response and returns the HTTP status stored in the * exception *
  2. NoMatchFoundException - Returns a 500 (Internal Server Error) *
  3. TimeoutException - Returns a 504 (Gateway Timeout) *
  4. Error | Exception - A 400 with an response payload containing the throwable's message *
*/ public class FiliDataExceptionHandler implements DataExceptionHandler { private static final Logger LOG = LoggerFactory.getLogger(FiliDataExceptionHandler.class); @Override public void handleThrowable( Throwable e, AsyncResponse asyncResponse, Optional apiRequest, ContainerRequestContext containerRequestContext, ObjectWriter writer ) { if (e instanceof RequestValidationException) { LOG.debug(e.getMessage(), e); RequestValidationException rve = (RequestValidationException) e; asyncResponse.resume(RequestHandlerUtils.makeErrorResponse(rve.getStatus(), rve, writer)); } else if (e instanceof NoMatchFoundException) { LOG.info( "Exception processing request: {}. Request: {}", e.getMessage(), containerRequestContext.getUriInfo().getRequestUri().toString() ); asyncResponse.resume(RequestHandlerUtils.makeErrorResponse(INTERNAL_SERVER_ERROR, e, writer)); } else if (e instanceof TimeoutException) { LOG.info( "Exception processing request: {}. Request: {}", e.getMessage(), containerRequestContext.getUriInfo().getRequestUri().toString() ); asyncResponse.resume(RequestHandlerUtils.makeErrorResponse(GATEWAY_TIMEOUT, e, writer)); } else { LOG.info( "Exception processing request: {}. Request: {}", e.getMessage(), containerRequestContext.getUriInfo().getRequestUri().toString() ); asyncResponse.resume(RequestHandlerUtils.makeErrorResponse(BAD_REQUEST, e, writer)); } } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy