Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
佳 邓
Gitlab4j Api
Commits
feeb3ab9
Commit
feeb3ab9
authored
Oct 28, 2018
by
Greg Messner
Browse files
Now customizes the message for validation errors (#260).
parent
b22a9301
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/main/java/org/gitlab4j/api/GitLabApiException.java
View file @
feeb3ab9
...
...
@@ -69,18 +69,28 @@ public class GitLabApiException extends Exception {
// If the node is an object, then it is validation errors
if
(
jsonMessage
.
isObject
())
{
StringBuilder
buf
=
new
StringBuilder
();
validationErrors
=
new
HashMap
<>();
Iterator
<
Entry
<
String
,
JsonNode
>>
fields
=
jsonMessage
.
fields
();
while
(
fields
.
hasNext
())
{
Entry
<
String
,
JsonNode
>
field
=
fields
.
next
();
String
fieldName
=
field
.
getKey
();
List
<
String
>
values
=
new
ArrayList
<>();
validationErrors
.
put
(
field
.
getKey
()
,
values
);
validationErrors
.
put
(
field
Name
,
values
);
for
(
JsonNode
value
:
field
.
getValue
())
{
values
.
add
(
value
.
asText
());
}
if
(
values
.
size
()
>
0
)
{
buf
.
append
((
buf
.
length
()
>
0
?
", "
:
""
)).
append
(
fieldName
);
}
}
if
(
buf
.
length
()
>
0
)
{
this
.
message
=
"The following fields have validation errors: "
+
buf
.
toString
();
}
}
else
{
this
.
message
=
jsonMessage
.
asText
();
}
...
...
@@ -131,7 +141,7 @@ public class GitLabApiException extends Exception {
/**
* Returns the HTTP status code that was the cause of the exception. returns 0 if the
* causing error was not an HTTP related exception
.
* causing error was not an HTTP related exception
*
* @return the HTTP status code, returns 0 if the causing error was not an HTTP related exception
*/
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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