Skip to content

Commit 912d318

Browse files
committed
feat: handle errors better
1 parent 1e888f6 commit 912d318

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

src/main/java/io/papermc/patchroulette/controller/RESTController.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@
55
import io.papermc.patchroulette.service.PatchService;
66
import java.util.List;
77
import org.springframework.beans.factory.annotation.Autowired;
8+
import org.springframework.http.HttpStatus;
89
import org.springframework.http.ResponseEntity;
910
import org.springframework.security.access.prepost.PreAuthorize;
1011
import org.springframework.security.core.Authentication;
12+
import org.springframework.web.bind.annotation.ExceptionHandler;
1113
import org.springframework.web.bind.annotation.GetMapping;
1214
import org.springframework.web.bind.annotation.PostMapping;
1315
import org.springframework.web.bind.annotation.RequestBody;
@@ -136,4 +138,8 @@ public ResponseEntity<String> login() {
136138
return ResponseEntity.ok("Your credentials are valid.");
137139
}
138140

141+
@ExceptionHandler(IllegalStateException.class)
142+
public ResponseEntity<String> handleException(final IllegalStateException e) {
143+
return ResponseEntity.status(HttpStatus.CONFLICT).body(e.getMessage());
144+
}
139145
}

0 commit comments

Comments
 (0)