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

com.formkiq.server.api.ErrorController Maven / Gradle / Ivy

package com.formkiq.server.api;

import static javax.servlet.http.HttpServletResponse.SC_INTERNAL_SERVER_ERROR;
import static javax.servlet.http.HttpServletResponse.SC_METHOD_NOT_ALLOWED;
import static javax.servlet.http.HttpServletResponse.SC_NOT_FOUND;

import javax.servlet.http.HttpServletResponse;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.formkiq.server.config.ApplicationConfig;

/**
 * HTML error status handler.
 *
 */
@RestController
public class ErrorController {

    /**
     * Handle 404.
     * @param response HttpServletResponse
     * @return ApiStringResponse
     */
	@RequestMapping(ApplicationConfig.API_ERROR_404)
	public ApiMessageResponse error404(final HttpServletResponse response) {
	    response.setStatus(SC_NOT_FOUND);
		return new ApiMessageResponse("invalid request url");
	}

	/**
     * Handle 405.
     * @param e Exception
     * @param response HttpServletResponse
     * @return ApiStringResponse
     */
	@RequestMapping(ApplicationConfig.API_ERROR_405)
    public ApiMessageResponse error405(final Exception e,
            final HttpServletResponse response) {
	    response.setStatus(SC_METHOD_NOT_ALLOWED);
		return new ApiMessageResponse("invalid method for url");
	}

	/**
     * Handle 500.
     * @param response HttpServletResponse
     * @return ApiStringResponse
     */
	@RequestMapping(ApplicationConfig.API_ERROR_500)
	public ApiMessageResponse error500(final HttpServletResponse response) {
	    response.setStatus(SC_INTERNAL_SERVER_ERROR);
        return new ApiMessageResponse("unable to process request");
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy