Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
J
java-gitlab-api
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
沈俊林
java-gitlab-api
Commits
1ae3f82a
Commit
1ae3f82a
authored
Nov 04, 2015
by
Tim Olshansky
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #92 from wikiwi/gitlab-exception
Expose HTTP Code through GitlabAPIException
parents
f328e64f
cb94dab0
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
27 additions
and
4 deletions
+27
-4
GitlabAPIException.java
src/main/java/org/gitlab/api/GitlabAPIException.java
+20
-0
GitlabHTTPRequestor.java
src/main/java/org/gitlab/api/http/GitlabHTTPRequestor.java
+4
-3
GitlabAPITest.java
src/test/java/org/gitlab/api/GitlabAPITest.java
+3
-1
No files found.
src/main/java/org/gitlab/api/GitlabAPIException.java
0 → 100644
View file @
1ae3f82a
package
org
.
gitlab
.
api
;
import
java.io.IOException
;
/**
* Gitlab API Exception
*/
public
class
GitlabAPIException
extends
IOException
{
private
int
responseCode
;
public
GitlabAPIException
(
String
message
,
Integer
responseCode
,
Throwable
cause
)
{
super
(
message
,
cause
);
this
.
responseCode
=
responseCode
;
}
public
int
getResponseCode
()
{
return
responseCode
;
}
}
src/main/java/org/gitlab/api/http/GitlabHTTPRequestor.java
View file @
1ae3f82a
...
...
@@ -3,6 +3,7 @@ package org.gitlab.api.http;
import
org.apache.commons.io.IOUtils
;
import
org.gitlab.api.AuthMethod
;
import
org.gitlab.api.GitlabAPI
;
import
org.gitlab.api.GitlabAPIException
;
import
org.gitlab.api.TokenType
;
import
org.gitlab.api.models.GitlabCommit
;
...
...
@@ -353,11 +354,11 @@ public class GitlabHTTPRequestor {
InputStream
es
=
wrapStream
(
connection
,
connection
.
getErrorStream
());
try
{
String
error
=
null
;
if
(
es
!=
null
)
{
throw
(
IOException
)
new
IOException
(
IOUtils
.
toString
(
es
,
"UTF-8"
)).
initCause
(
e
);
}
else
{
throw
e
;
error
=
IOUtils
.
toString
(
es
,
"UTF-8"
);
}
throw
new
GitlabAPIException
(
error
,
connection
.
getResponseCode
(),
e
);
}
finally
{
IOUtils
.
closeQuietly
(
es
);
}
...
...
src/test/java/org/gitlab/api/GitlabAPITest.java
View file @
1ae3f82a
...
...
@@ -32,10 +32,12 @@ public class GitlabAPITest {
api
.
dispatch
().
with
(
"login"
,
"INVALID"
).
with
(
"password"
,
rand
).
to
(
"session"
,
GitlabUser
.
class
);
}
catch
(
ConnectException
e
)
{
assumeNoException
(
"GITLAB not running on '"
+
TEST_URL
+
"', skipping..."
,
e
);
}
catch
(
IO
Exception
e
)
{
}
catch
(
GitlabAPI
Exception
e
)
{
final
String
message
=
e
.
getMessage
();
if
(!
message
.
equals
(
"{\"message\":\"401 Unauthorized\"}"
))
{
throw
new
AssertionError
(
"Expected an unauthorized message"
,
e
);
}
else
if
(
e
.
getResponseCode
()
!=
401
)
{
throw
new
AssertionError
(
"Expected 401 code"
,
e
);
}
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment