Invalid application/json in request

291 views
Skip to first unread message

Andrew Allen

unread,
Jul 30, 2018, 12:37:18 AM7/30/18
to repo-discuss
I've spent the evening playing with the REST API, but I keep getting back a less than helpful "Invalid application/json in request" error with a http status code of 400.

From the docs:

"""
“400 Bad Request” is also returned if required input fields are not set or if options are set which cannot be used together.
"""

I understand that my request is flawed in its formulation, but is there any way to get it to tell me what validation my request failed specifically?  It doesn't look like there are any flags, config options, or query parameters related to expanding the error output. I looked in both the response body and the Gerrit logs. Does anyone have any theories beyond that?

/** ~Andrew Z Allen */

Edwin Kempin

unread,
Jul 30, 2018, 2:28:54 AM7/30/18
to m...@andrewzallen.com, Repo and Gerrit Discussion
Often the response body contains an error string that gives a hint about what is wrong.
Beyond that there is no switch to get more output.
What's the request that you are sending?
 

/** ~Andrew Z Allen */

--
--
To unsubscribe, email repo-discuss...@googlegroups.com
More info at http://groups.google.com/group/repo-discuss?hl=en

---
You received this message because you are subscribed to the Google Groups "Repo and Gerrit Discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to repo-discuss...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Andrew Allen

unread,
Jul 31, 2018, 1:26:24 AM7/31/18
to Edwin Kempin, repo-discuss
Edwin,

On Mon, Jul 30, 2018 at 12:28 AM Edwin Kempin <eke...@google.com> wrote:
On Mon, Jul 30, 2018 at 6:37 AM Andrew Allen <m...@andrewzallen.com> wrote:
I've spent the evening playing with the REST API, but I keep getting back a less than helpful "Invalid application/json in request" error with a http status code of 400.

From the docs:

"""
“400 Bad Request” is also returned if required input fields are not set or if options are set which cannot be used together.
"""

I understand that my request is flawed in its formulation, but is there any way to get it to tell me what validation my request failed specifically?  It doesn't look like there are any flags, config options, or query parameters related to expanding the error output. I looked in both the response body and the Gerrit logs. Does anyone have any theories beyond that?
Often the response body contains an error string that gives a hint about what is wrong.
Beyond that there is no switch to get more output.
What's the request that you are sending?

I've managed to narrow it down to something I'm doing when I pass it in as "robot_comments". When I pass

```
 {"message":"Robot comments","tag":"robot","comments":{"demo.file":[{"id":"41976821557229542092103641930910809939.0","line":2,"updated":"2018-07
-31 05:20:06.394464977","message":"Example comment to demonstrate"}]},"drafts":"PUBLISH_ALL_REVISIONS","notify":"NONE","omit_duplicate_comments":true}
```

The comment is left successfully on the code.

However when I pass the same in the `robot_comments` (and the required fields filled) like this:

```
{"message":"Robot comments","tag":"robot","robot_comments":{"demo.file":[{"id":"41976821557229542092103641930910809939.0","line":3,"updated":"2018-07-31 05:20:42.915378055","message":"Example comment to demonstrate","robot_id":"Manual","robot_run_id":"41976821557229542092103641930910809939","url":"","properties":null,"fix_suggestions":{"fix_id":"","description":"","replacements":{"path":"","range":{"start_line":0,"start_character":0,"end_line":0,"end_character":0},"replacement":""}}}]},"drafts":"PUBLISH_ALL_REVISIONS","notify":"NONE","omit_duplicate_comments":true}
```

The complete response from the server is:

"Invalid application/json in request"

Any thoughts on that?

Andrew Allen

unread,
Jul 31, 2018, 2:09:36 AM7/31/18
to Edwin Kempin, repo-discuss
On Mon, Jul 30, 2018 at 11:26 PM Andrew Allen <m...@andrewzallen.com> wrote:
Edwin,

On Mon, Jul 30, 2018 at 12:28 AM Edwin Kempin <eke...@google.com> wrote:
On Mon, Jul 30, 2018 at 6:37 AM Andrew Allen <m...@andrewzallen.com> wrote:
I've spent the evening playing with the REST API, but I keep getting back a less than helpful "Invalid application/json in request" error with a http status code of 400.

From the docs:

"""
“400 Bad Request” is also returned if required input fields are not set or if options are set which cannot be used together.
"""

I understand that my request is flawed in its formulation, but is there any way to get it to tell me what validation my request failed specifically?  It doesn't look like there are any flags, config options, or query parameters related to expanding the error output. I looked in both the response body and the Gerrit logs. Does anyone have any theories beyond that?
Often the response body contains an error string that gives a hint about what is wrong.
Beyond that there is no switch to get more output.
What's the request that you are sending?

I've managed to narrow it down to something I'm doing when I pass it in as "robot_comments". When I pass

```
 {"message":"Robot comments","tag":"robot","comments":{"demo.file":[{"id":"41976821557229542092103641930910809939.0","line":2,"updated":"2018-07
-31 05:20:06.394464977","message":"Example comment to demonstrate"}]},"drafts":"PUBLISH_ALL_REVISIONS","notify":"NONE","omit_duplicate_comments":true}
```

The comment is left successfully on the code.

However when I pass the same in the `robot_comments` (and the required fields filled) like this:

```
{"message":"Robot comments","tag":"robot","robot_comments":{"demo.file":[{"id":"41976821557229542092103641930910809939.0","line":3,"updated":"2018-07-31 05:20:42.915378055","message":"Example comment to demonstrate","robot_id":"Manual","robot_run_id":"41976821557229542092103641930910809939","url":"","properties":null,"fix_suggestions":{"fix_id":"","description":"","replacements":{"path":"","range":{"start_line":0,"start_character":0,"end_line":0,"end_character":0},"replacement":""}}}]},"drafts":"PUBLISH_ALL_REVISIONS","notify":"NONE","omit_duplicate_comments":true}
```

The complete response from the server is:

"Invalid application/json in request"

Any thoughts on that?

As is usual, the answer is, I'm dumb and need to read better. That is invalid in many ways. Path needs to be filled and the line numbers need to be non-zero. I've since corrected those (and learned a bunch about JSON serialization in Golang) and it works, but it would be nice if the errors were less opaque.

Thanks for your help Edwin!
Reply all
Reply to author
Forward
0 new messages