From 0ca25d4f46088c723e65c3a9614e4f280777013c Mon Sep 17 00:00:00 2001 From: Adam Date: Thu, 26 Nov 2020 14:21:14 -0500 Subject: [PATCH] chat controller: return 404 if task is not found This was returning a 200 with an empty body, causing the client to npe due to deserializing it as a Task with no task or location --- .../http/service/chat/ChatController.java | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/http-service/src/main/java/net/runelite/http/service/chat/ChatController.java b/http-service/src/main/java/net/runelite/http/service/chat/ChatController.java index ccba9db430..8632a8b2f0 100644 --- a/http-service/src/main/java/net/runelite/http/service/chat/ChatController.java +++ b/http-service/src/main/java/net/runelite/http/service/chat/ChatController.java @@ -34,6 +34,9 @@ import net.runelite.http.api.chat.LayoutRoom; import net.runelite.http.api.chat.Task; import net.runelite.http.service.util.exception.NotFoundException; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.CacheControl; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; @@ -155,9 +158,18 @@ public class ChatController } @GetMapping("/task") - public Task getTask(@RequestParam String name) + public ResponseEntity getTask(@RequestParam String name) { - return chatService.getTask(name); + Task task = chatService.getTask(name); + if (task == null) + { + return ResponseEntity.status(HttpStatus.NOT_FOUND) + .build(); + } + + return ResponseEntity.ok() + .cacheControl(CacheControl.maxAge(2, TimeUnit.MINUTES).cachePublic()) + .body(task); } @PostMapping("/pb")