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

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

/*
 * Copyright (C) 2016 FormKiQ Inc.
 *
 * 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.
 */

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