Skip to content

Handling Responses

Olivia edited this page Apr 18, 2021 · 3 revisions

Handling Responses

Every possible response always contains JSON. And every returned JSON always returns a "success", whether true or false.

If success is true, a "response" parameter is specified. Otherwise, it will not appear.

Status codes also indicate what the issue is.

Response Codes

The server can respond with various different codes. See below for what happened and why.

200 OK

This means your request worked and is good! Check for a response.

400 Bad Request

This is sent for one of many reasons:

  1. A username or uuid parameter was not specified when POSTing.
  2. No Method was provided.
  3. You're doing something really weird with the request, just do it right, please.

401 Unauthoized

This is only sent when a key is required, but the provided key (if any) is incorrect.

404 Not Found

This is sent when you try to access a route that isn't configured. If you're getting this after modifying the config, try /jrareload.

405 Not Allowed

This is sent when you send a request with an invalid or incorrect method.

Unexpected Responses

If the program fails to handle your input, you may get some interesting issues.

Sometimes you may get a "socket hang up":

socket hang up

This means the server was unable to handle your response properly, so it can't even give you one.

Debug steps:

  1. Set debug to true in config.yml
  2. Run /jrareload
  3. Do your request
  4. Check your server console
  5. Copy all lines starting with "Received request" all the way to the end of the WARN stack trace. For example:
[01:34:50 INFO]: [JSONRestAPI] Received request: POST /?key=CHANGE_ME_PLEASE&request=%server_tps_10%&username=ChewLeKitten HTTP/1.1
[01:34:50 INFO]: [JSONRestAPI] Added parameter key with value CHANGE_ME_PLEASE
[01:34:50 INFO]: [JSONRestAPI] Added parameter request with value %server_tps_10%
[01:34:50 INFO]: [JSONRestAPI] Added parameter username with value ChewLeKitten
[01:34:50 INFO]: [JSONRestAPI] Route: 
[01:34:50 WARN]: Exception in thread "Thread-23" java.util.UnknownFormatConversionException: Conversion = '}'
[01:34:50 WARN]: 	at java.base/java.util.Formatter.checkText(Formatter.java:2748)
[01:34:50 WARN]: 	at java.base/java.util.Formatter.parse(Formatter.java:2734)
[01:34:50 WARN]: 	at java.base/java.util.Formatter.format(Formatter.java:2671)
[01:34:50 WARN]: 	at java.base/java.io.PrintWriter.format(PrintWriter.java:991)
[01:34:50 WARN]: 	at java.base/java.io.PrintWriter.printf(PrintWriter.java:888)
[01:34:50 WARN]: 	at pw.chew.jsonrestapi.RestServer$ServerResponder.respondOk(RestServer.java:273)
[01:34:50 WARN]: 	at pw.chew.jsonrestapi.RestServer$ServerResponder.run(RestServer.java:154)

Then take this information and make an issue. Please ensure you are up to date, as well!