001/*
002 * Copyright (c) 2010-2024 Mark Allen, Norbert Bartels.
003 *
004 * Permission is hereby granted, free of charge, to any person obtaining a copy
005 * of this software and associated documentation files (the "Software"), to deal
006 * in the Software without restriction, including without limitation the rights
007 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
008 * copies of the Software, and to permit persons to whom the Software is
009 * furnished to do so, subject to the following conditions:
010 *
011 * The above copyright notice and this permission notice shall be included in
012 * all copies or substantial portions of the Software.
013 *
014 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
015 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
016 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
017 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
018 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
019 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
020 * THE SOFTWARE.
021 */
022package com.restfb.exception;
023
024import com.restfb.json.JsonObject;
025
026/**
027 * immutable container to transfer all data used to create the correct facebook exception
028 */
029public class ExceptionInformation {
030
031  /**
032   * Old REST API exception error code field, e.g. 190.
033   */
034  private final Integer errorCode;
035
036  /**
037   * Old REST API exception error subcode field, e.g. 459.
038   */
039  private final Integer errorSubcode;
040
041  /**
042   * The HTTP status code returned by the server, e.g. 500.
043   */
044  private final Integer httpStatusCode;
045
046  /**
047   * Graph API exception type field, e.g. "OAuthException".
048   */
049  private final String type;
050
051  /**
052   * Graph or Old REST API message field, e.g. "Invalid access token signature."
053   */
054  private final String message;
055
056  /**
057   * Graph API error_user_title field.
058   */
059  private final String userTitle;
060
061  /**
062   * Graph API error_user_message field.
063   */
064  private final String userMessage;
065
066  private final Boolean isTransient;
067
068  /**
069   * raw error message as JSON
070   */
071  private final JsonObject rawError;
072
073  /**
074   * basic constructor to build a set of information used by the exception generator
075   * 
076   * @param errorCode
077   *          Old REST API exception error code field, e.g. 190.
078   * @param httpStatusCode
079   *          The HTTP status code returned by the server, e.g. 500.
080   * @param message
081   *          Graph or Old REST API message field, e.g. "Invalid access token signature."
082   * @param rawError
083   *          raw error message as JSON
084   */
085  public ExceptionInformation(Integer errorCode, Integer httpStatusCode, String message, JsonObject rawError) {
086    this(errorCode, null, httpStatusCode, null, message, null, null, null, rawError);
087  }
088
089  /**
090   * extended constructor to build a set of information used by the exception generator
091   *
092   * @param errorCode
093   *          Old REST API exception error code field, e.g. 190.
094   * @param errorSubcode
095   *          Old REST API exception error subcode field, e.g. 459.
096   * @param httpStatusCode
097   *          The HTTP status code returned by the server, e.g. 500.
098   * @param type
099   *          Graph API exception type field, e.g. "OAuthException".
100   * @param message
101   *          Graph or Old REST API message field, e.g. "Invalid access token signature."
102   * @param userTitle
103   *          Graph API error_user_title field.
104   * @param userMessage
105   *          Graph API error_user_message field.
106   * @param rawError
107   *          raw error message as JSON
108   */
109  public ExceptionInformation(Integer errorCode, Integer errorSubcode, Integer httpStatusCode, String type,
110      String message, String userTitle, String userMessage, Boolean isTransient, JsonObject rawError) {
111    this.errorCode = errorCode;
112    this.errorSubcode = errorSubcode;
113    this.httpStatusCode = httpStatusCode;
114    this.type = type;
115    this.message = message;
116    this.userTitle = userTitle;
117    this.userMessage = userMessage;
118    this.isTransient = isTransient;
119    this.rawError = rawError;
120  }
121
122  public Integer getErrorCode() {
123    return errorCode;
124  }
125
126  public Integer getErrorSubcode() {
127    return errorSubcode;
128  }
129
130  public Integer getHttpStatusCode() {
131    return httpStatusCode;
132  }
133
134  public String getType() {
135    return type;
136  }
137
138  public String getMessage() {
139    return message;
140  }
141
142  public String getUserTitle() {
143    return userTitle;
144  }
145
146  public String getUserMessage() {
147    return userMessage;
148  }
149
150  public Boolean getIsTransient() {
151    return isTransient;
152  }
153
154  public JsonObject getRawError() {
155    return rawError;
156  }
157}