-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Changed error format to model messaging sdk
- Loading branch information
1 parent
f944e38
commit 0aec289
Showing
5 changed files
with
84 additions
and
18 deletions.
There are no files selected for viewing
18 changes: 0 additions & 18 deletions
18
src/main/java/com/bandwidth/sdk/numbers/NumbersException.java
This file was deleted.
Oops, something went wrong.
18 changes: 18 additions & 0 deletions
18
src/main/java/com/bandwidth/sdk/numbers/exception/NumbersClientException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package com.bandwidth.sdk.numbers.exception; | ||
|
||
|
||
public class NumbersClientException extends RuntimeException { | ||
|
||
|
||
public NumbersClientException(String message) { | ||
super(message); | ||
} | ||
|
||
public NumbersClientException(Throwable cause) { | ||
super(cause); | ||
} | ||
|
||
public NumbersClientException(String message, Throwable cause) { | ||
super(message, cause); | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
src/main/java/com/bandwidth/sdk/numbers/exception/NumbersServiceException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package com.bandwidth.sdk.numbers.exception; | ||
|
||
import com.bandwidth.sdk.numbers.models.NumbersApiError; | ||
import org.asynchttpclient.Response; | ||
|
||
public class NumbersServiceException extends RuntimeException { | ||
|
||
private NumbersApiError error; | ||
|
||
public NumbersServiceException(NumbersApiError error) { | ||
super(error.toString()); | ||
this.error = error; | ||
} | ||
|
||
public NumbersApiError getError() { | ||
return error; | ||
} | ||
|
||
public static void throwIfApiError(Response apiResponse) { | ||
if (!isSuccessfulHttpStatusCode(apiResponse.getStatusCode())) { | ||
try { | ||
throw new NumbersServiceException( | ||
//TODO: After NumbersSerde() is created, change this to something like this: | ||
//new NumbersSerde().deserialize(apiResponse.getResponseBody(), NumbersApiError.class) | ||
new NumbersApiError() | ||
); | ||
} catch (Exception e) { | ||
throw new NumbersClientException("Unknown error response from API: " + apiResponse); | ||
} | ||
} | ||
} | ||
|
||
static boolean isSuccessfulHttpStatusCode(int statusCode) { | ||
return (statusCode / 100) == 2; | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
src/main/java/com/bandwidth/sdk/numbers/models/NumbersApiError.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package com.bandwidth.sdk.numbers.models; | ||
|
||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize; | ||
import com.fasterxml.jackson.databind.annotation.JsonSerialize; | ||
import org.immutables.value.Value; | ||
|
||
import java.util.List; | ||
|
||
@Value.Immutable | ||
@JsonSerialize(as = ImmutableNumbersApiError.class) | ||
@JsonDeserialize(as = ImmutableNumbersApiError.class) | ||
public abstract class NumbersApiError { | ||
public abstract String getType(); | ||
public abstract String getDescription(); | ||
public abstract List<NumbersApiFieldError> getFieldErrors(); | ||
} |
14 changes: 14 additions & 0 deletions
14
src/main/java/com/bandwidth/sdk/numbers/models/NumbersApiFieldError.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package com.bandwidth.sdk.numbers.models; | ||
|
||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize; | ||
import com.fasterxml.jackson.databind.annotation.JsonSerialize; | ||
import org.immutables.value.Value; | ||
|
||
@Value.Immutable | ||
@JsonSerialize(as = ImmutableNumbersApiFieldError.class) | ||
@JsonDeserialize(as = ImmutableNumbersApiFieldError.class) | ||
public abstract class NumbersApiFieldError { | ||
public abstract String getFieldName(); | ||
public abstract String getDescription(); | ||
|
||
} |