diff options
author | Kevin Sawicki | 2011-05-30 23:36:18 +0000 |
---|---|---|
committer | Kevin Sawicki | 2011-05-30 23:36:18 +0000 |
commit | d3bab40e0781bb782c66404d434abd28685cdad6 (patch) | |
tree | 3c5dbe1456718108e4b84fbbb67619ab20cd6e1a /org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/internal/github | |
parent | 404affd46652f10b3b8f8cc52251d4fb8c42a3f4 (diff) | |
download | egit-github-d3bab40e0781bb782c66404d434abd28685cdad6.tar.gz egit-github-d3bab40e0781bb782c66404d434abd28685cdad6.tar.xz egit-github-d3bab40e0781bb782c66404d434abd28685cdad6.zip |
Use wrapped exception when validating repo settings.
RequestException thrown during repository validation needs
to be wrapped in GitHubException to have properly
formatted messages displayed in the wizard message area.
This change migrates exception handling to always wrap
RequestException inside a GitHubException when caught.
Change-Id: I464948f7ca14e818e840bf482c301b7d96f5b2ba
Signed-off-by: Kevin Sawicki <kevin@github.com>
Diffstat (limited to 'org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/internal/github')
6 files changed, 36 insertions, 14 deletions
diff --git a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/internal/github/core/GitHub.java b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/internal/github/core/GitHub.java index 6206ad0f..064e7629 100644 --- a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/internal/github/core/GitHub.java +++ b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/internal/github/core/GitHub.java @@ -12,6 +12,7 @@ *******************************************************************************/ package org.eclipse.mylyn.internal.github.core; +import java.io.IOException; import java.util.regex.Pattern; import org.eclipse.core.runtime.ILog; @@ -19,6 +20,7 @@ import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Platform; import org.eclipse.core.runtime.Status; import org.eclipse.egit.github.core.Repository; +import org.eclipse.egit.github.core.client.RequestException; /** * GitHub class @@ -98,6 +100,17 @@ public class GitHub { } /** + * Create error status from {@link IOException} that wraps it in a + * {@link GitHubException} if it is a {@link RequestException} + * + * @param e + * @return status + */ + public static IStatus createWrappedStatus(IOException e) { + return createErrorStatus(GitHubException.wrap(e)); + } + + /** * Get log * * @return log diff --git a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/internal/github/core/GitHubException.java b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/internal/github/core/GitHubException.java index a0a58cf7..4048b65d 100644 --- a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/internal/github/core/GitHubException.java +++ b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/internal/github/core/GitHubException.java @@ -29,6 +29,19 @@ public class GitHubException extends IOException { private static final long serialVersionUID = -1456910662911777231L; /** + * Wraps the given {@link IOException} with a {@link GitHubException} if it + * is a {@link RequestException} instance. + * + * @param exception + * @return wrapped exception + */ + public static IOException wrap(IOException exception) { + return exception instanceof RequestException ? new GitHubException( + (RequestException) exception) : exception; + + } + + /** * Create GitHub exception from {@link RequestException} * * @param cause diff --git a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/internal/github/core/gist/GistAttachmentHandler.java b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/internal/github/core/gist/GistAttachmentHandler.java index 833f349a..d35abe9f 100644 --- a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/internal/github/core/gist/GistAttachmentHandler.java +++ b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/internal/github/core/gist/GistAttachmentHandler.java @@ -69,7 +69,7 @@ public class GistAttachmentHandler extends AbstractTaskAttachmentHandler { throw new IOException("Unable to obtain raw file URL from Gist"); //$NON-NLS-1$ return new URL(urlAttribute.getValue()).openStream(); } catch (IOException e) { - throw new CoreException(GitHub.createErrorStatus(e)); + throw new CoreException(GitHub.createWrappedStatus(e)); } } @@ -111,7 +111,7 @@ public class GistAttachmentHandler extends AbstractTaskAttachmentHandler { file.setContent(output.toString()); service.updateGist(gist); } catch (IOException e) { - throw new CoreException(GitHub.createErrorStatus(e)); + throw new CoreException(GitHub.createWrappedStatus(e)); } finally { try { input.close(); diff --git a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/internal/github/core/gist/GistConnector.java b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/internal/github/core/gist/GistConnector.java index 11f08457..24f6f888 100644 --- a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/internal/github/core/gist/GistConnector.java +++ b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/internal/github/core/gist/GistConnector.java @@ -138,7 +138,7 @@ public class GistConnector extends AbstractRepositoryConnector { return data; } catch (IOException e) { - throw new CoreException(GitHub.createErrorStatus(e)); + throw new CoreException(GitHub.createWrappedStatus(e)); } } @@ -206,7 +206,7 @@ public class GistConnector extends AbstractRepositoryConnector { collector.accept(data); } } catch (IOException e) { - status = GitHub.createErrorStatus(e); + status = GitHub.createWrappedStatus(e); } return status; } diff --git a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/internal/github/core/gist/GistTaskDataHandler.java b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/internal/github/core/gist/GistTaskDataHandler.java index e68a2900..3e22ecb2 100644 --- a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/internal/github/core/gist/GistTaskDataHandler.java +++ b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/internal/github/core/gist/GistTaskDataHandler.java @@ -231,7 +231,7 @@ public class GistTaskDataHandler extends AbstractTaskDataHandler { try { gist = service.createGist(gist); } catch (IOException e) { - throw new CoreException(GitHub.createErrorStatus(e)); + throw new CoreException(GitHub.createWrappedStatus(e)); } response = new RepositoryResponse(ResponseKind.TASK_CREATED, gist.getId()); @@ -244,7 +244,7 @@ public class GistTaskDataHandler extends AbstractTaskDataHandler { service.updateGist(gist); } catch (IOException e) { - throw new CoreException(GitHub.createErrorStatus(e)); + throw new CoreException(GitHub.createWrappedStatus(e)); } response = new RepositoryResponse(ResponseKind.TASK_UPDATED, taskData.getTaskId()); diff --git a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/internal/github/core/issue/IssueConnector.java b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/internal/github/core/issue/IssueConnector.java index d74fce97..3f978788 100644 --- a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/internal/github/core/issue/IssueConnector.java +++ b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/internal/github/core/issue/IssueConnector.java @@ -33,7 +33,6 @@ import org.eclipse.egit.github.core.Label; import org.eclipse.egit.github.core.Milestone; import org.eclipse.egit.github.core.Repository; import org.eclipse.egit.github.core.client.GitHubClient; -import org.eclipse.egit.github.core.client.RequestException; import org.eclipse.egit.github.core.service.IssueService; import org.eclipse.egit.github.core.service.LabelService; import org.eclipse.egit.github.core.service.MilestoneService; @@ -43,7 +42,6 @@ import org.eclipse.mylyn.commons.net.AuthenticationCredentials; import org.eclipse.mylyn.commons.net.AuthenticationType; import org.eclipse.mylyn.commons.net.Policy; import org.eclipse.mylyn.internal.github.core.GitHub; -import org.eclipse.mylyn.internal.github.core.GitHubException; import org.eclipse.mylyn.internal.github.core.QueryUtils; import org.eclipse.mylyn.tasks.core.AbstractRepositoryConnector; import org.eclipse.mylyn.tasks.core.IRepositoryQuery; @@ -120,7 +118,7 @@ public class IssueConnector extends AbstractRepositoryConnector { this.repositoryLabels.put(repository, labels); return labels; } catch (IOException e) { - throw new CoreException(GitHub.createErrorStatus(e)); + throw new CoreException(GitHub.createWrappedStatus(e)); } } @@ -173,7 +171,7 @@ public class IssueConnector extends AbstractRepositoryConnector { this.repositoryMilestones.put(repository, milestones); return milestones; } catch (IOException e) { - throw new CoreException(GitHub.createErrorStatus(e)); + throw new CoreException(GitHub.createWrappedStatus(e)); } } @@ -307,10 +305,8 @@ public class IssueConnector extends AbstractRepositoryConnector { } monitor.worked(1); } - } catch (RequestException e) { - result = GitHub.createErrorStatus(new GitHubException(e)); } catch (IOException e) { - result = GitHub.createErrorStatus(e); + result = GitHub.createWrappedStatus(e); } monitor.done(); @@ -335,7 +331,7 @@ public class IssueConnector extends AbstractRepositoryConnector { return taskDataHandler.createTaskData(repository, monitor, repo.getOwner(), repo.getName(), issue, comments); } catch (IOException e) { - throw new CoreException(GitHub.createErrorStatus(e)); + throw new CoreException(GitHub.createWrappedStatus(e)); } } |