FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Utility Exception : AxisFault cannot be cast to ApiException · Issue #53 · googleads/googleads-java-lib · GitHub

Utility Exception : AxisFault cannot be cast to ApiException #53

Description

A bug that I used to correct in my code and that should be resolved definitly now ;-) As it's a very old bug (since the first versions), I guess there is few users of the Utility, no ?

Here it goes :

Exception in thread "main" java.lang.ClassCastException: org.apache.axis.AxisFault cannot be cast to com.google.api.ads.adwords.axis.v201506.cm.ApiException
    at com.google.api.ads.adwords.axis.utility.extension.exception.UtilityLibraryException.getUnwrapApiExceptions(UtilityLibraryException.java:98)
    at com.google.api.ads.adwords.axis.utility.extension.util.ReflectionUtil.invokeCount(ReflectionUtil.java:142)
    at com.google.api.ads.adwords.axis.utility.extension.util.ReflectionUtil.invokeCount(ReflectionUtil.java:74)

And this is what I use to add in UtilityLibraryException.java :

/**
     * Unwraps ApiException, AxisFault and RemoteException exceptions
     *
     * @param exception the {@code Exception} to unwrap
     * @param message custom message to include in the UtilityLibraryException
     * @throws RemoteException for communication-related exceptions
     */
    public static void throwUnwrapApiExceptions(Exception exception, String message)
            throws RemoteException {
        Throwable throwable = Throwables.getRootCause(exception);
        if (throwable.getClass().isAssignableFrom(ApiException.class)) {
            throw (ApiException) throwable;
        }
        if (throwable.getClass().isAssignableFrom(RemoteException.class)) {
            throw (RemoteException) throwable;
        }
        if (throwable.getClass().isAssignableFrom(AxisFault.class)) {
            throw (AxisFault) throwable;
        }

        throw new UtilityLibraryException(message, exception);
    }

    /**
     * Unwraps ApiException, AxisFault and RemoteException exceptions
     *
     * @param exception the {@code Exception} to unwrap
     * @param message custom message to include in the UtilityLibraryException
     * @return the unwrapped RemoteException
     */
    public static RemoteException getUnwrapApiExceptions(Exception exception, String message) {
        Throwable throwable = Throwables.getRootCause(exception);

        if (throwable.getClass().isAssignableFrom(ApiException.class)
                && !throwable.getClass().equals(RemoteException.class)
                && !throwable.getClass().equals(AxisFault.class)) {
            return (ApiException) throwable;
        }
        if (throwable.getClass().isAssignableFrom(RemoteException.class)) {
            return (RemoteException) throwable;
        }

        if (throwable.getClass().isAssignableFrom(AxisFault.class)) {
            return (AxisFault) throwable;
        }

        return new RemoteException(message + " " + throwable.getMessage(), throwable);
    }

Cheers.

David Botella

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions


Back | FazBrowse Home | New Git URL