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

org.kiwiproject.jaxrs.exception.JaxrsNotFoundException Maven / Gradle / Ivy

Go to download

Kiwi is a utility library. We really like Google's Guava, and also use Apache Commons. But if they don't have something we need, and we think it is useful, this is where we put it.

There is a newer version: 4.4.0
Show newest version
package org.kiwiproject.jaxrs.exception;

/**
 * Exception representing a 404 Not Found that extends {@link JaxrsException} to use Kiwi's {@link ErrorMessage}.
 */
public class JaxrsNotFoundException extends JaxrsException {

    /**
     * The status code for all instances of this exception.
     */
    public static final int CODE = 404;

    /**
     * New instance with given cause and 404 status code.
     *
     * @param cause the cause of this exception
     */
    public JaxrsNotFoundException(Throwable cause) {
        super(cause, CODE);
    }

    /**
     * New instance with given message and 404 status code.
     *
     * @param message the message for this exception
     */
    public JaxrsNotFoundException(String message) {
        super(message, CODE);
    }

    /**
     * New instance with given message, cause, and 404 status code.
     *
     * @param message the message for this exception
     * @param cause   the cause of this exception
     */
    public JaxrsNotFoundException(String message, Throwable cause) {
        super(message, cause, CODE);
    }

    /**
     * New instance with given type and item ID. Resulting message is built using {@link #buildMessage(String, Object)}.
     *
     * @param type   the type of object that was not found
     * @param itemId the unique key/identifier of the object that was not found
     */
    public JaxrsNotFoundException(String type, String itemId) {
        super(buildMessage(type, itemId), CODE);
    }

    /**
     * New instance with given type and item ID. Resulting message is built using {@link #buildMessage(String, Object)}.
     *
     * @param type   the type of object that was not found
     * @param itemId the unique key/identifier of the object that was not found
     */
    public JaxrsNotFoundException(String type, Object itemId) {
        super(buildMessage(type, itemId), CODE);
    }

    /**
     * Build a generic "not found" message using the given type and key.
     * 

* Format: [type] [key] wsa not found. *

* Example: User 42 was not found. * * @param type the type of object that was not found * @param key the unique key/identifier of the object that was not found * @return the generic "not found" message */ public static String buildMessage(String type, Object key) { return type + " " + key + " was not found."; } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy