Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added custom NumbersException class #15

Closed
wants to merge 6 commits into from

Conversation

jmulford-bw
Copy link
Contributor

closes #14

NathanNorman
NathanNorman previously approved these changes Nov 7, 2018
Copy link
Contributor

@fuchsnj fuchsnj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Messaging SDK has 2 exceptions. One ServiceException for non 2xx responses from the api server, and a ClientException for other stuff. Can you follow this same pattern if it makes sense for the numbers api?
https://github.com/Bandwidth/messaging-java-sdk/blob/master/src/main/java/com/bandwidth/sdk/messaging/exception/MessagingClientException.java
https://github.com/Bandwidth/messaging-java-sdk/blob/master/src/main/java/com/bandwidth/sdk/messaging/exception/MessagingServiceException.java

@jmulford-bw
Copy link
Contributor Author

I'll just make the NumbersSerde in this PR and close #17 as well to make the travis scripts happy

@Value.Immutable
@JsonSerialize(as = ImmutableNumbersApiError.class)
@JsonDeserialize(as = ImmutableNumbersApiError.class)
public abstract class NumbersApiError {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the Numbers error's look different than our Messages api. We should probably just remove this (And NumbersApiFieldError)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that's right. Based on the docs, all of the responses look like this

<BillingReportCreationResponse>
    <ResponseStatus>
        <ErrorCode>15501</ErrorCode>
        <Description>Invalid date range. Start date 2014-05-21 must be before end date 2013-05-29</Description>
    </ResponseStatus>
</BillingReportCreationResponse>

All have the same ResponseStatus fields, but the outer tag looks different for all of them

public static void throwIfApiError(Response apiResponse) {
if (!isSuccessfulHttpStatusCode(apiResponse.getStatusCode())) {
try {
throw new NumbersServiceException(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code that was copied here had a bug: https://github.com/Bandwidth/messaging-java-sdk/pull/40/files


import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
import com.fasterxml.jackson.datatype.jdk8.Jdk8Module;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This import isn't needed.

@NathanNorman NathanNorman self-assigned this Nov 9, 2018

import java.util.concurrent.CompletableFuture;

public class ExceptionUtils {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see this used pattern in Messaging SDK and Number SDK (with only the Exception name being different). Might make sense to pull this out functionality to a shared lib.

@jmulford-bw
Copy link
Contributor Author

Already done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Custom exception class
5 participants