Skip to content

Commit a53e097

Browse files
committed
feat: handle errors better
1 parent 515bb84 commit a53e097

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

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

Lines changed: 7 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;
@@ -126,4 +128,9 @@ public ResponseEntity<String> undoPatch(final Authentication auth, @RequestBody
126128
this.patchService.undoPatch(input, user);
127129
return ResponseEntity.ok("Patch moved to WIP.");
128130
}
131+
132+
@ExceptionHandler(IllegalStateException.class)
133+
public ResponseEntity<String> handleException(final IllegalStateException e) {
134+
return ResponseEntity.status(HttpStatus.CONFLICT).body(e.getMessage());
135+
}
129136
}

0 commit comments

Comments
 (0)