001/*
002 *  Copyright 2024 Anyware Services
003 *
004 *  Licensed under the Apache License, Version 2.0 (the "License");
005 *  you may not use this file except in compliance with the License.
006 *  You may obtain a copy of the License at
007 *
008 *      http://www.apache.org/licenses/LICENSE-2.0
009 *
010 *  Unless required by applicable law or agreed to in writing, software
011 *  distributed under the License is distributed on an "AS IS" BASIS,
012 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 *  See the License for the specific language governing permissions and
014 *  limitations under the License.
015 */
016package org.ametys.plugins.pagesubscription;
017
018/**
019 * Common exception for all subscriptions.
020 */
021public class SubscriptionException extends RuntimeException
022{
023    private Type _type;
024    
025    /**
026     * The type of the exception.
027     */
028    public enum Type
029    {
030        /** The subscription already exist */
031        ALREADY_EXIST,
032        /** An user different of the subscriber try to access to the subscription */
033        NO_ACCESS,
034        /** Unknown errors */
035        UNKNOWN;
036    }
037    
038    /**
039     * Constructs a new SubscriptionException.
040     */
041    public SubscriptionException()
042    {
043        super();
044        _type = Type.UNKNOWN;
045    }
046    
047    /**
048     * Constructs a new SubscriptionException with the specified message.
049     * @param message the message of the exception.
050     */
051    public SubscriptionException(String message)
052    {
053        super(message);
054        _type = Type.UNKNOWN;
055    }
056    
057    /**
058     * Constructs a new SubscriptionException with the specified message.
059     * @param message the message of the exception.
060     * @param type the type of the exception
061     */
062    public SubscriptionException(String message, Type type)
063    {
064        super(message);
065        _type = type;
066    }
067    
068    /**
069     * Constructs a new SubscriptionException with the specified message and cause.
070     * @param message the message of the exception.
071     * @param cause the cause of the exception.
072     */
073    public SubscriptionException(String message, Throwable cause)
074    {
075        super(message, cause);
076        _type = Type.UNKNOWN;
077    }
078    
079    /**
080     * Constructs a new SubscriptionException with the specified message and cause.
081     * @param message the message of the exception.
082     * @param cause the cause of the exception.
083     * @param type the type of the exception
084     */
085    public SubscriptionException(String message, Throwable cause, Type type)
086    {
087        super(message, cause);
088        _type = type;
089    }
090    
091    /**
092     * Constructs a new SubscriptionException with the specified cause.
093     * @param cause the cause of the exception.
094     */
095    public SubscriptionException(Throwable cause)
096    {
097        super(cause);
098        _type = Type.UNKNOWN;
099    }
100    
101    /**
102     * Constructs a new SubscriptionException with the specified cause.
103     * @param cause the cause of the exception.
104     * @param type the type of the exception
105     */
106    public SubscriptionException(Throwable cause, Type type)
107    {
108        super(cause);
109        _type = type;
110    }
111    
112    /**
113     * Get the type of the exception
114     * @return the type
115     */
116    public Type getType()
117    {
118        return _type;
119    }
120}