001package com.nimbusds.oauth2.sdk; 002 003 004import java.net.URL; 005 006import com.nimbusds.oauth2.sdk.id.State; 007 008 009/** 010 * The base class for exceptions defined in this SDK. 011 * 012 * @author Vladimir Dzhuvinov 013 */ 014public class GeneralException extends Exception { 015 016 017 /** 018 * The associated error, {@code null} if not specified. 019 */ 020 private final ErrorObject error; 021 022 023 /** 024 * The redirection URI, {@code null} if not specified or redirection is 025 * not to be performed for this error. Implies a HTTP status code 302. 026 */ 027 private final URL redirectURI; 028 029 030 /** 031 * Optional state parameter, {@code null} if not specified. 032 */ 033 private final State state; 034 035 036 /** 037 * Creates a new general exception. 038 * 039 * @param message The exception message. May be {@code null}. 040 */ 041 public GeneralException(final String message) { 042 043 this(message, null); 044 } 045 046 047 /** 048 * Creates a new general exception. 049 * 050 * @param message The exception message. May be {@code null}. 051 * @param cause The exception cause, {@code null} if not specified. 052 */ 053 public GeneralException(final String message, final Throwable cause) { 054 055 this(message, null, cause); 056 } 057 058 059 /** 060 * Creates a new general exception. 061 * 062 * @param message The exception message. May be {@code null}. 063 * @param error The associated error, {@code null} if not specified. 064 * @param cause The exception cause, {@code null} if not specified. 065 */ 066 public GeneralException(final String message, 067 final ErrorObject error, 068 final Throwable cause) { 069 070 this(message, error, null, null, cause); 071 } 072 073 074 /** 075 * Creates a new general exception. 076 * 077 * @param message The exception message. May be {@code null}. 078 * @param error The associated error, {@code null} if not 079 * specified. 080 * @param redirectURI The associated redirection URI, {@code null} if 081 * not specified. 082 * @param state The optional associated state parameter, 083 * {@code null} if not specified. 084 */ 085 public GeneralException(final String message, 086 final ErrorObject error, 087 final URL redirectURI, 088 final State state) { 089 090 this(message, error, redirectURI, state, null); 091 } 092 093 094 /** 095 * Creates a new general exception. 096 * 097 * @param message The exception message. May be {@code null}. 098 * @param error The associated error, {@code null} if not 099 * specified. 100 * @param redirectURI The associated redirection URI, {@code null} if 101 * not specified. 102 * @param state The optional associated state parameter, 103 * {@code null} if not specified. 104 * @param cause The exception cause, {@code null} if not 105 * specified. 106 */ 107 public GeneralException(final String message, 108 final ErrorObject error, 109 final URL redirectURI, 110 final State state, 111 final Throwable cause) { 112 113 super(message, cause); 114 115 this.error = error; 116 this.redirectURI = redirectURI; 117 this.state = state; 118 } 119 120 121 /** 122 * Gets the associated error. 123 * 124 * @return The error, {@code null} if not specified. 125 */ 126 public ErrorObject getErrorObject() { 127 128 return error; 129 } 130 131 132 /** 133 * Gets the associated redirection URI. 134 * 135 * @return The redirection URI, {@code null} if redirection is not to 136 * be performed for this error. 137 */ 138 public URL getRedirectURI() { 139 140 return redirectURI; 141 } 142 143 144 /** 145 * Gets the optional associated state parameter. 146 * 147 * @return The optional state parameter, {@code null} if not specified 148 * or redirection is not to be performed. 149 */ 150 public State getState() { 151 152 return state; 153 } 154}