Example usage for com.google.api.client.googleapis.json GoogleJsonError getMessage

List of usage examples for com.google.api.client.googleapis.json GoogleJsonError getMessage

Introduction

In this page you can find the example usage for com.google.api.client.googleapis.json GoogleJsonError getMessage.

Prototype

public final String getMessage() 

Source Link

Document

Returns the human-readable explanation of the error or null for none.

Usage

From source file:calendariotaller.CalendarSample.java

License:Apache License

private static void addCalendarsUsingBatch() throws IOException {
    View.header("Add Calendars using Batch");
    BatchRequest batch = client.batch();

    // Create the callback.
    JsonBatchCallback<Calendar> callback = new JsonBatchCallback<Calendar>() {

        @Override// w  ww .ja v a 2  s .c  o m
        public void onSuccess(Calendar calendar, HttpHeaders responseHeaders) {
            View.display(calendar);
            addedCalendarsUsingBatch.add(calendar);
        }

        @Override
        public void onFailure(GoogleJsonError e, HttpHeaders responseHeaders) {
            System.out.println("Error Message: " + e.getMessage());
        }
    };

    // Create 2 Calendar Entries to insert.
    Calendar entry1 = new Calendar().setSummary("Calendar for Testing 1");
    client.calendars().insert(entry1).queue(batch, callback);

    Calendar entry2 = new Calendar().setSummary("Calendar for Testing 2");
    client.calendars().insert(entry2).queue(batch, callback);

    batch.execute();
}

From source file:calendariotaller.CalendarSample.java

License:Apache License

private static void deleteCalendarsUsingBatch() throws IOException {
    View.header("Delete Calendars Using Batch");
    BatchRequest batch = client.batch();
    for (Calendar calendar : addedCalendarsUsingBatch) {
        client.calendars().delete(calendar.getId()).queue(batch, new JsonBatchCallback<Void>() {

            @Override//from www  . j  a v  a 2 s  .  c  om
            public void onSuccess(Void content, HttpHeaders responseHeaders) {
                System.out.println("Delete is successful!");
            }

            @Override
            public void onFailure(GoogleJsonError e, HttpHeaders responseHeaders) {
                System.out.println("Error Message: " + e.getMessage());
            }
        });
    }

    batch.execute();
}

From source file:calendar_cmdline_sample.CalendarSample.java

License:Apache License

@SuppressWarnings("unused")
private static void addCalendarsUsingBatch() throws IOException {
    View.header("Add Calendars using Batch");
    BatchRequest batch = client.batch();

    // Create the callback.
    JsonBatchCallback<Calendar> callback = new JsonBatchCallback<Calendar>() {

        @Override/*w  w w  . j ava2s  . c  o  m*/
        public void onSuccess(Calendar calendar, HttpHeaders responseHeaders) {
            View.display(calendar);
            addedCalendarsUsingBatch.add(calendar);
        }

        @Override
        public void onFailure(GoogleJsonError e, HttpHeaders responseHeaders) {
            System.out.println("Error Message: " + e.getMessage());
        }
    };

    // Create 2 Calendar Entries to insert.
    Calendar entry1 = new Calendar().setSummary("Calendar for Testing 1");
    client.calendars().insert(entry1).queue(batch, callback);

    Calendar entry2 = new Calendar().setSummary("Calendar for Testing 2");
    client.calendars().insert(entry2).queue(batch, callback);

    batch.execute();
}

From source file:calendar_cmdline_sample.CalendarSample.java

License:Apache License

@SuppressWarnings("unused")
private static void deleteCalendarsUsingBatch() throws IOException {
    View.header("Delete Calendars Using Batch");
    BatchRequest batch = client.batch();
    for (Calendar calendar : addedCalendarsUsingBatch) {
        client.calendars().delete(calendar.getId()).queue(batch, new JsonBatchCallback<Void>() {

            @Override//  w  w w .j  a  v  a2  s.c o  m
            public void onSuccess(Void content, HttpHeaders responseHeaders) {
                System.out.println("Delete is successful!");
            }

            @Override
            public void onFailure(GoogleJsonError e, HttpHeaders responseHeaders) {
                System.out.println("Error Message: " + e.getMessage());
            }
        });
    }

    batch.execute();
}

From source file:ch.codezombie.insightsdashboard.Utils.java

License:Apache License

/**
 * Logs the given throwable and shows an error alert dialog with its message.
 *
 * @param activity activity/*  w  w w  .  j ava  2 s . c  om*/
 * @param tag      log tag to use
 * @param t        throwable to log and show
 */
public static void logAndShow(Activity activity, String tag, Throwable t) {
    Log.e(tag, "Error", t);
    String message = t.getMessage();
    if (t instanceof GoogleJsonResponseException) {
        GoogleJsonError details = ((GoogleJsonResponseException) t).getDetails();
        if (details != null) {
            message = details.getMessage();
        }
    } else if (t.getCause() instanceof GoogleAuthException) {
        message = ((GoogleAuthException) t.getCause()).getMessage();
    }
    showError(activity, message);
}

From source file:ch.cyberduck.core.googledrive.DriveBatchDeleteFeature.java

License:Open Source License

@Override
public void delete(final List<Path> files, final LoginCallback prompt, final Callback callback)
        throws BackgroundException {
    final BatchRequest batch = session.getClient().batch();
    final List<BackgroundException> failures = new ArrayList<>();
    for (Path file : files) {
        try {//from  w  w w.  j  a  v  a2s  .  c  o  m
            session.getClient().files().delete(new DriveFileidProvider(session).getFileid(file)).queue(batch,
                    new JsonBatchCallback<Void>() {
                        @Override
                        public void onFailure(final GoogleJsonError e, final HttpHeaders responseHeaders)
                                throws IOException {
                            log.warn(String.format("Failure deleting %s. %s", file, e.getMessage()));
                            failures.add(new HttpResponseExceptionMappingService()
                                    .map(new HttpResponseException(e.getCode(), e.getMessage())));
                        }

                        @Override
                        public void onSuccess(final Void aVoid, final HttpHeaders responseHeaders)
                                throws IOException {
                            callback.delete(file);
                        }
                    });
        } catch (IOException e) {
            throw new DriveExceptionMappingService().map("Cannot delete {0}", e, file);
        }
    }
    try {
        batch.execute();
    } catch (IOException e) {
        throw new DriveExceptionMappingService().map(e);
    }
    for (BackgroundException e : failures) {
        throw e;
    }
}

From source file:com.battlelancer.seriesguide.backend.CloudEndpointUtils.java

License:Apache License

/**
 * Logs the given throwable and shows an error alert dialog with its
 * message./*from   ww  w  .ja v a 2 s . com*/
 *
 * @param activity
 *            activity
 * @param tag
 *            log tag to use
 * @param t
 *            throwable to log and show
 */
public static void logAndShow(Activity activity, String tag, Throwable t) {
    Log.e(tag, "Error", t);
    String message = t.getMessage();
    // Exceptions that occur in your Cloud Endpoint implementation classes
    // are wrapped as GoogleJsonResponseExceptions
    if (t instanceof GoogleJsonResponseException) {
        GoogleJsonError details = ((GoogleJsonResponseException) t).getDetails();
        if (details != null) {
            message = details.getMessage();
        }
    }
    showError(activity, message);
}

From source file:com.bibibig.yeon.navitest.CalendarList.AsyncBatchInsertCalendarList.java

License:Apache License

@Override
protected void doInBackground() throws IOException {
    BatchRequest batch = client.batch();
    for (Calendar calendar : calendars) {
        client.calendars().insert(calendar).setFields(BasicInfo.CALFIELDS).queue(batch,
                new JsonBatchCallback<Calendar>() {

                    public void onSuccess(Calendar calendar, HttpHeaders headers) {
                        model.add(calendar);
                    }/*from   www  .j a  v  a2  s  .  c o m*/

                    @Override
                    public void onFailure(GoogleJsonError err, HttpHeaders headers) throws IOException {
                        Utils.logAndShowError(activity, MainActivity.TAG, err.getMessage());
                    }
                });
    }
    batch.execute();
}

From source file:com.dankift.orienteernfc.cloudbackend.CloudEndpointUtils.java

License:Apache License

/**
 * Logs the given throwable and shows an error alert dialog with its message.
 * /*from ww w  .j  a  v a 2  s.  c  om*/
 * @param activity
 *          activity
 * @param tag
 *          log tag to use
 * @param t
 *          throwable to log and show
 */
public static void logAndShow(Activity activity, String tag, Throwable t) {
    Log.e(tag, "Error", t);
    String message = t.getMessage();
    if (t instanceof GoogleJsonResponseException) {
        GoogleJsonError details = ((GoogleJsonResponseException) t).getDetails();
        if (details != null) {
            message = details.getMessage();
        }
    }
    showError(activity, message);
}

From source file:com.example.eventgooglecalendar.asynctasks.AsyncBatchInsertCalendars.java

License:Apache License

@Override
protected void doInBackground() throws IOException {
    BatchRequest batch = client.batch();
    for (Calendar calendar : calendars) {
        client.calendars().insert(calendar).setFields(CalendarInfo.FIELDS).queue(batch,
                new JsonBatchCallback<Calendar>() {

                    public void onSuccess(Calendar calendar, HttpHeaders headers) {
                        model.add(calendar);
                    }/*from   w w  w .ja v a 2s .  c om*/

                    @Override
                    public void onFailure(GoogleJsonError err, HttpHeaders headers) throws IOException {
                        Utils.logAndShowError(activity, CalendarSampleActivity.TAG, err.getMessage());
                    }
                });
    }
    batch.execute();
}