Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect HTTP code (200) on POST with empty string #1260

Closed
elbow-jason opened this issue Jul 26, 2017 · 8 comments
Closed

Incorrect HTTP code (200) on POST with empty string #1260

elbow-jason opened this issue Jul 26, 2017 · 8 comments
Assignees
Labels
kind/maintenance Maintenance tasks, such as refactoring, with no impact in features.
Milestone

Comments

@elbow-jason
Copy link

elbow-jason commented Jul 26, 2017

What happened:

When POSTing an empty string to the /query path the response comes back with a 200 HTTP code, but the json clearly indicates an error.

What I expected to happen:

When POSTing an empty string to the /query path the response comes back with a 400 or a 422 HTTP code to indicate that something was wrong with the request from the client.

An example:

$ curl -X POST http://127.0.0.1:8080/query -d "" -v
*   Trying 127.0.0.1...
* Connected to 127.0.0.1 (127.0.0.1) port 8080 (#0)
> POST /query HTTP/1.1
> Host: 127.0.0.1:8080
> User-Agent: curl/7.43.0
> Accept: */*
> Content-Length: 0
> Content-Type: application/x-www-form-urlencoded
>
< HTTP/1.1 200 OK
< Access-Control-Allow-Credentials: true
< Access-Control-Allow-Headers: Content-Type, Content-Length, Accept-Encoding, X-CSRF-Token,X-Auth-Token, Cache-Control, X-Requested-With
< Access-Control-Allow-Methods: POST, OPTIONS
< Access-Control-Allow-Origin: *
< Connection: close
< Date: Wed, 26 Jul 2017 08:04:40 GMT
< Content-Length: 71
< Content-Type: text/plain; charset=utf-8
<
* Closing connection 0
{"code":"ErrorInvalidRequest","message":"Invalid request encountered."}⏎
@manishrjain manishrjain added the kind/maintenance Maintenance tasks, such as refactoring, with no impact in features. label Jul 27, 2017
@manishrjain manishrjain added this to the v0.8.1 milestone Jul 27, 2017
@manishrjain
Copy link
Contributor

Would be good to check what GraphQL providers typically do in this case -- do they always send back 200, or do they change the http codes. From my understanding, they rely upon errors field: http://facebook.github.io/graphql/#sec-Data

@elbow-jason
Copy link
Author

It looks like the convention in graphql is to ignore http codes and rely on the structure of the responses. This is due to some graphql servers being able to return partially successful results and errors simultaneously. In the facebook spec (the link above) they API is returning a map with two entries at it's root data for successful partial queries and errors for any reportable errors that occurred. It may be necessary to incorporate this scoping of data to data and errors to errors fields so that successful query results are clearly distinguishable from errors.

For example, I can imaging a scenario where I am storing my dgraph query errors in a dgraph itself (meta, right?) and I ask for code and message as fields in my query and the response is {"code":"ErrorInvalidRequest","message":"Invalid request encountered."}. The question is: Is this the good response to my query or an error?

@pawanrawal
Copy link
Contributor

We could add data key to the response but I feel that just makes parsing a bit harder. For each block now you must access it through the data key.

@elbow-jason
Copy link
Author

I agree, accessing all results through data is not ideal. But there must be something that differentiates a good response from a bad response. Without some method of differentiation we are left with a leaky abstraction. Perhaps the just the errors could be placed into errors and then document that it is not recommended to use a errors(func: ....) {} as a query?

@pawanrawal
Copy link
Contributor

We can make sure that every time there is an error, the http status code is 400. Would that work?

@elbow-jason
Copy link
Author

That would work very well!

@manishrjain
Copy link
Contributor

Sorry, I disagree with @pawanrawal's assessment here. If GraphQL does 200 + {data, errors}, then we should do the same. They deliberately tried to stay away from REST's conception of using http codes to indicate issues, instead keeping http code OK, and returning a JSON response. So, we should stick to it. Over time, we want to be closer to how GraphQL does things than go further away from it.

@pawanrawal
Copy link
Contributor

We now send an errors key in case there is an error. A successful response is nested under the data key. This is in accordance with the GraphQL spec.

@manishrjain manishrjain added the kind/maintenance Maintenance tasks, such as refactoring, with no impact in features. label Mar 22, 2018
jarifibrahim pushed a commit that referenced this issue Mar 16, 2020
Important changes
```
 - Changes to overlap check in compaction.
 - Remove 'this entry should've been caught' log.
 - Changes to write stalling on levels 0 and 1.
 - Compression is disabled by default in Badger.
 - Bloom filter caching in a separate ristretto cache.
 - Compression/Encryption in background.
 - Disable cache by default in badger.
```

The following new changes are being added from badger
`git log ab4352b00a17...91c31ebe8c22`

```
91c31eb Disable cache by default (#1257)
eaf64c0 Add separate cache for bloom filters (#1260)
1bcbefc Add BypassDirLock option (#1243)
c6c1e5e Add support for watching nil prefix in subscribe API (#1246)
b13b927 Compress/Encrypt Blocks in the background (#1227)
bdb2b13 fix changelog for v2.0.2 (#1244)
8dbc982 Add Dkron to README (#1241)
3d95b94 Remove coveralls from Travis Build(#1219)
5b4c0a6 Fix ValueThreshold for in-memory mode (#1235)
617ed7c Initialize vlog before starting compactions in db.Open (#1226)
e908818 Update CHANGELOG for Badger 2.0.2 release. (#1230)
bce069c Fix int overflow for 32bit (#1216)
e029e93 Remove ExampleDB_Subscribe Test (#1214)
8734e3a Add missing package to README for badger.NewEntry (#1223)
78d405a Replace t.Fatal with require.NoError in tests (#1213)
c51748e Fix flaky TestPageBufferReader2 test (#1210)
eee1602 Change else-if statements to idiomatic switch statements. (#1207)
3e25d77 Rework concurrency semantics of valueLog.maxFid (#1184) (#1187)
4676ca9 Add support for caching bloomfilters (#1204)
c3333a5 Disable compression and set ZSTD Compression Level to 1 (#1191)
0acb3f6 Fix L0/L1 stall test (#1201)
7e5a956 Support disabling the cache completely. (#1183) (#1185)
82381ac Update ristretto to version  8f368f2 (#1195)
3747be5 Improve write stalling on level 0 and 1
5870b7b Run all tests on CI (#1189)
01a00cb Add Jaegar to list of projects (#1192)
9d6512b Use fastRand instead of locked-rand in skiplist (#1173)
2698bfc Avoid sync in inmemory mode (#1190)
2a90c66 Remove the 'this entry should've caught' log from value.go (#1170)
0a06173 Fix checkOverlap in compaction (#1166)
0f2e629 Fix windows build (#1177)
03af216 Fix commit sha for WithInMemory in CHANGELOG. (#1172)
23a73cd Update CHANGELOG for v2.0.1 release. (#1181)
465f28a Cast sz to uint32 to fix compilation on 32 bit (#1175)
ea01d38 Rename option builder from WithInmemory to WithInMemory. (#1169)
df99253 Remove ErrGCInMemoryMode in CHANGELOG. (#1171)
8dfdd6d Adding changes for 2.0.1 so far (#1168)
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/maintenance Maintenance tasks, such as refactoring, with no impact in features.
Development

No branches or pull requests

4 participants