package be.ac.ulb.code.wit.resources.serializers.helpers;

import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.Response;

public class UnauthorizedException extends WebApplicationException {
	private static final long serialVersionUID = 1873195154804536511L;
	private static int UNAUTHORIZED = 401;

	/**
	 * Constructs a UnauthorizedException, without any specific associated
	 * description of the exception.
	 */
	public UnauthorizedException() {
		super(Response.status(UNAUTHORIZED).build());
	}

	/**
	 * Constructs a UnauthorizedException, with the specified message describing
	 * the exception.
	 * 
	 * @param message
	 *            The String that describes why the exception was thrown and
	 *            that is used in the response to the client.
	 */
	public UnauthorizedException(String message) {
		super(Response.status(UNAUTHORIZED).entity(message).type("text/plain")
				.build());
	}

	/**
	 * Constructs a UnauthorizedException, with the specified underlying cause.
	 * 
	 * @param cause
	 *            The underlying cause of the exception. The message of this
	 *            cause is used in the response to the client.
	 */
	public UnauthorizedException(Throwable cause) {
		super(cause, Response.status(UNAUTHORIZED).entity(cause.getMessage())
				.type("text/plain").build());
	}

	/**
	 * Constructs a UnauthorizedException, with the specified cause and message
	 * describing the exception.
	 * 
	 * @param cause
	 *            The underlying cause of the exception.
	 * @param message
	 *            The String that describes why the exception was thrown and
	 *            that is used in the response to the client.
	 */
	public UnauthorizedException(String message, Throwable cause) {
		super(cause, Response.status(UNAUTHORIZED).entity(message)
				.type("text/plain").build());
	}
}
