HttpException.java
/***************************************************************************
Copyright 2014 Emily Estes
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 net.metanotion.web.concrete;
import net.metanotion.web.HttpValues;
/** This exception works with the {@link net.metanotion.web.concrete.SimpleSessionHandler} to communicate HTTP error
responses via exceptions. Obviously, it is possible for some code to swallow runtime exceptions, and this is not a
perfect mechanism, however this exception provides a mechanism that application writers and library writers can
consider. This exception is created with an HTTP status code as it's parameter. If
{@link net.metanotion.web.concrete.SimpleSessionHandler} catches this exception it just returns the HTTP Response this
exception stores which simply encodes an HTTP status code response. */
public final class HttpException extends RuntimeException {
private final HttpValues result;
/** Create a new HTTP Exception with a default status code of "500 Internal Server Error". */
public HttpException() { this.result = HttpUtil.new500("Internal Server Error"); }
/** Create a new HTTP Exception with a specific HTTP status code.
@param httpStatus The HTTP status code of the response this exception encodes.
*/
public HttpException(final int httpStatus) { this.result = HttpUtil.newStatus(httpStatus); }
/** Create a new HTTP Exception with a specific HTTP response.
@param response The HTTP status code of the response this exception encodes.
*/
public HttpException(final HttpValues response) { this.result = response; }
/** Retrieve the HTTP Response this exception encodes.
@return An HTTP response returning an error status.
*/
public HttpValues getHttpResponse() { return this.result; }
@Override public Throwable fillInStackTrace() { return null; }
}