Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
46 changes: 43 additions & 3 deletions src/main/java/com/twilio/exception/ApiException.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,12 @@ public class ApiException extends TwilioException {
private static final long serialVersionUID = -3228320166955630014L;

private final Integer code;
private final String moreInfo;
private final Integer status;
private final Map<String, Object> details;
private String moreInfo;
private Integer status;
private Map<String, Object> details;
private Integer httpStatusCode;
private Boolean userError;
private Map<String, Object> params;

/**
* Create a new API Exception.
Expand Down Expand Up @@ -40,6 +43,7 @@ public ApiException(final String message, final Integer status) {
this(message, null, null, status, null);
}


/**
* Create a new API Exception.
*
Expand All @@ -58,6 +62,18 @@ public ApiException(final String message, final Integer code, final String moreI
this.details = null;
}


public ApiException(final Integer code, final String message, final Integer httpStatusCode, final Boolean userError,
final Throwable cause, String moreInfo, Integer status, Map<String, Object> details) {
super(message, cause);
this.code = code;
this.httpStatusCode = httpStatusCode;
this.userError = userError;
this.moreInfo = moreInfo;
this.status = status;
this.details = details;
this.params = null;
}
/**
* Create a new API Exception.
*
Expand All @@ -71,6 +87,18 @@ public ApiException(final RestException restException) {
this.details = restException.getDetails();
}

/**
* Create V1.0 standard Rest Exception
* @return restException as RestExceptionV10
*/
public ApiException(final RestExceptionV10 restException) {
super(restException.getMessage(), null);
this.code = restException.getCode();
this.httpStatusCode = restException.getHttpStatusCode();
this.userError = restException.getUserError();
this.params = restException.getParams();
}

public Integer getCode() {
return code;
}
Expand All @@ -86,4 +114,16 @@ public Integer getStatusCode() {
public Map<String, Object> getDetails() {
return details;
}

public Integer getHttpStatusCode() {
return httpStatusCode;
}

public Boolean getUserError() {
return userError;
}

public Map<String, Object> getParams() {
return params;
}
}
80 changes: 80 additions & 0 deletions src/main/java/com/twilio/exception/RestExceptionV10.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
package com.twilio.exception;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.io.IOException;
import java.io.InputStream;
import java.util.Map;

/**
* Rest Exception V1.0 for Twilio API Standards
*/
public class RestExceptionV10 {

private final Integer code;
private final String message;
private final Integer httpStatusCode;
private final Boolean userError;
private final Map<String, Object> params;

/**
* Initialize a Twilio Rest Exception.
*
* @param code Twilio-specific error code
* @param message A human readable error message
* @param httpStatusCode HTTP response status code
* @param userError whether the error is a user error (true) or a system error (false)
* @param params A map of parameters related to the error, for example, a `params.twilioErrorCodeUrl` might hold a URL or link to additional information
*/
@JsonCreator
private RestExceptionV10(@JsonProperty("code") final int code, @JsonProperty("message") final String message,
@JsonProperty("httpStatusCode") final Integer httpStatusCode, @JsonProperty("userError") final boolean userError,
@JsonProperty("params") final Map<String, Object> params) {
this.code = code;
this.message = message;
this.httpStatusCode = httpStatusCode;
this.userError = userError;
this.params = params;
}

/**
* Build an exception from a JSON blob.
*
* @param json JSON blob
* @param objectMapper JSON reader
* @return Rest Exception as an object
*/
public static RestExceptionV10 fromJson(final InputStream json, final ObjectMapper objectMapper) {
// Convert all checked exception to Runtime
try {
return objectMapper.readValue(json, RestExceptionV10.class);
} catch (final JsonMappingException | JsonParseException e) {
throw new ApiException(e.getMessage(), e);
} catch (final IOException e) {
throw new ApiConnectionException(e.getMessage(), e);
}
}

public Integer getCode() {
return code;
}

public String getMessage() {
return message;
}

public Integer getHttpStatusCode() {
return httpStatusCode;
}

public Boolean getUserError() {
return userError;
}

public Map<String, Object> getParams() {
return params;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ private Page<Aws> pageForRequest(
response.getStream(),
client.getObjectMapper()
);

if (restException == null) {
throw new ApiException(
"Server Error, no content",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ private Page<PublicKey> pageForRequest(
response.getStream(),
client.getObjectMapper()
);

if (restException == null) {
throw new ApiException(
"Server Error, no content",
Expand Down
1 change: 0 additions & 1 deletion src/main/java/com/twilio/rest/api/v2010/AccountReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ private Page<Account> pageForRequest(
response.getStream(),
client.getObjectMapper()
);

if (restException == null) {
throw new ApiException(
"Server Error, no content",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ private Page<Address> pageForRequest(
response.getStream(),
client.getObjectMapper()
);

if (restException == null) {
throw new ApiException(
"Server Error, no content",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ private Page<Application> pageForRequest(
response.getStream(),
client.getObjectMapper()
);

if (restException == null) {
throw new ApiException(
"Server Error, no content",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ private Page<AuthorizedConnectApp> pageForRequest(
response.getStream(),
client.getObjectMapper()
);

if (restException == null) {
throw new ApiException(
"Server Error, no content",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ private Page<AvailablePhoneNumberCountry> pageForRequest(
response.getStream(),
client.getObjectMapper()
);

if (restException == null) {
throw new ApiException(
"Server Error, no content",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,6 @@ private Page<Call> pageForRequest(
response.getStream(),
client.getObjectMapper()
);

if (restException == null) {
throw new ApiException(
"Server Error, no content",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,6 @@ private Page<Conference> pageForRequest(
response.getStream(),
client.getObjectMapper()
);

if (restException == null) {
throw new ApiException(
"Server Error, no content",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ private Page<ConnectApp> pageForRequest(
response.getStream(),
client.getObjectMapper()
);

if (restException == null) {
throw new ApiException(
"Server Error, no content",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@ private Page<IncomingPhoneNumber> pageForRequest(
response.getStream(),
client.getObjectMapper()
);

if (restException == null) {
throw new ApiException(
"Server Error, no content",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ private Page<Key> pageForRequest(
response.getStream(),
client.getObjectMapper()
);

if (restException == null) {
throw new ApiException(
"Server Error, no content",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,6 @@ private Page<Message> pageForRequest(
response.getStream(),
client.getObjectMapper()
);

if (restException == null) {
throw new ApiException(
"Server Error, no content",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ private Page<Notification> pageForRequest(
response.getStream(),
client.getObjectMapper()
);

if (restException == null) {
throw new ApiException(
"Server Error, no content",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ private Page<OutgoingCallerId> pageForRequest(
response.getStream(),
client.getObjectMapper()
);

if (restException == null) {
throw new ApiException(
"Server Error, no content",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ private Page<Queue> pageForRequest(
response.getStream(),
client.getObjectMapper()
);

if (restException == null) {
throw new ApiException(
"Server Error, no content",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,6 @@ private Page<Recording> pageForRequest(
response.getStream(),
client.getObjectMapper()
);

if (restException == null) {
throw new ApiException(
"Server Error, no content",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ private Page<ShortCode> pageForRequest(
response.getStream(),
client.getObjectMapper()
);

if (restException == null) {
throw new ApiException(
"Server Error, no content",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ private Page<SigningKey> pageForRequest(
response.getStream(),
client.getObjectMapper()
);

if (restException == null) {
throw new ApiException(
"Server Error, no content",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ private Page<Transcription> pageForRequest(
response.getStream(),
client.getObjectMapper()
);

if (restException == null) {
throw new ApiException(
"Server Error, no content",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ private Page<DependentPhoneNumber> pageForRequest(
response.getStream(),
client.getObjectMapper()
);

if (restException == null) {
throw new ApiException(
"Server Error, no content",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,6 @@ private Page<Local> pageForRequest(
response.getStream(),
client.getObjectMapper()
);

if (restException == null) {
throw new ApiException(
"Server Error, no content",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,6 @@ private Page<MachineToMachine> pageForRequest(
response.getStream(),
client.getObjectMapper()
);

if (restException == null) {
throw new ApiException(
"Server Error, no content",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,6 @@ private Page<Mobile> pageForRequest(
response.getStream(),
client.getObjectMapper()
);

if (restException == null) {
throw new ApiException(
"Server Error, no content",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,6 @@ private Page<National> pageForRequest(
response.getStream(),
client.getObjectMapper()
);

if (restException == null) {
throw new ApiException(
"Server Error, no content",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,6 @@ private Page<SharedCost> pageForRequest(
response.getStream(),
client.getObjectMapper()
);

if (restException == null) {
throw new ApiException(
"Server Error, no content",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,6 @@ private Page<TollFree> pageForRequest(
response.getStream(),
client.getObjectMapper()
);

if (restException == null) {
throw new ApiException(
"Server Error, no content",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,6 @@ private Page<Voip> pageForRequest(
response.getStream(),
client.getObjectMapper()
);

if (restException == null) {
throw new ApiException(
"Server Error, no content",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ private Page<Event> pageForRequest(
response.getStream(),
client.getObjectMapper()
);

if (restException == null) {
throw new ApiException(
"Server Error, no content",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@ private Page<Notification> pageForRequest(
response.getStream(),
client.getObjectMapper()
);

if (restException == null) {
throw new ApiException(
"Server Error, no content",
Expand Down
Loading
Loading