Skip to content

Commit ad069ba

Browse files
committed
Add Accept: application/json header to all API requests
Fixes JSON parse error when server returns non-JSON responses (e.g. on validation failures for empty player lists).
1 parent 2adb5c2 commit ad069ba

1 file changed

Lines changed: 7 additions & 0 deletions

File tree

src/main/java/com/mcsets/setstore/api/SetStoreAPI.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ public class SetStoreAPI {
3838

3939
private static final MediaType JSON = MediaType.get("application/json; charset=utf-8");
4040
private static final String HEADER_API_KEY = "X-API-Key";
41+
private static final String HEADER_ACCEPT = "Accept";
42+
private static final String APPLICATION_JSON = "application/json";
4143

4244
private final SetStorePlugin plugin;
4345
private final OkHttpClient client;
@@ -115,6 +117,7 @@ public QueueResponse getQueue() {
115117
Request request = new Request.Builder()
116118
.url(baseUrl + "/queue")
117119
.header(HEADER_API_KEY, apiKey)
120+
.header(HEADER_ACCEPT, APPLICATION_JSON)
118121
.get()
119122
.build();
120123

@@ -155,6 +158,7 @@ public ApiResponse reportDelivery(int deliveryId, String status, List<String> ac
155158
Request request = new Request.Builder()
156159
.url(baseUrl + "/deliver")
157160
.header(HEADER_API_KEY, apiKey)
161+
.header(HEADER_ACCEPT, APPLICATION_JSON)
158162
.post(RequestBody.create(json, JSON))
159163
.build();
160164

@@ -188,6 +192,7 @@ public ApiResponse reportOnlinePlayers(List<String> players) {
188192
Request request = new Request.Builder()
189193
.url(baseUrl + "/online")
190194
.header(HEADER_API_KEY, apiKey)
195+
.header(HEADER_ACCEPT, APPLICATION_JSON)
191196
.post(RequestBody.create(json, JSON))
192197
.build();
193198

@@ -215,6 +220,7 @@ public HeartbeatResponse heartbeat() {
215220
Request request = new Request.Builder()
216221
.url(baseUrl + "/heartbeat")
217222
.header(HEADER_API_KEY, apiKey)
223+
.header(HEADER_ACCEPT, APPLICATION_JSON)
218224
.post(RequestBody.create("{}", JSON))
219225
.build();
220226

@@ -248,6 +254,7 @@ public VerifyResponse verify(String username, String uuid) {
248254
Request request = new Request.Builder()
249255
.url(baseUrl + "/verify")
250256
.header(HEADER_API_KEY, apiKey)
257+
.header(HEADER_ACCEPT, APPLICATION_JSON)
251258
.post(RequestBody.create(json, JSON))
252259
.build();
253260

0 commit comments

Comments
 (0)