1 | package edu.ucsb.cs156.courses.controllers; | |
2 | ||
3 | import edu.ucsb.cs156.courses.errors.EntityNotFoundException; | |
4 | import edu.ucsb.cs156.courses.errors.BadEnrollCdException; | |
5 | import net.bytebuddy.implementation.bytecode.Throw; | |
6 | import org.springframework.beans.factory.annotation.Autowired; | |
7 | ||
8 | import edu.ucsb.cs156.courses.models.CurrentUser; | |
9 | import edu.ucsb.cs156.courses.services.CurrentUserService; | |
10 | import lombok.extern.slf4j.Slf4j; | |
11 | import org.springframework.http.HttpStatus; | |
12 | import org.springframework.web.bind.annotation.ExceptionHandler; | |
13 | import org.springframework.web.bind.annotation.ResponseStatus; | |
14 | ||
15 | import java.util.Map; | |
16 | ||
17 | @Slf4j | |
18 | public abstract class ApiController { | |
19 | @Autowired | |
20 | private CurrentUserService currentUserService; | |
21 | ||
22 | protected CurrentUser getCurrentUser() { | |
23 |
1
1. getCurrentUser : replaced return value with null for edu/ucsb/cs156/courses/controllers/ApiController::getCurrentUser → KILLED |
return currentUserService.getCurrentUser(); |
24 | } | |
25 | ||
26 | protected Object genericMessage(String message) { | |
27 |
1
1. genericMessage : replaced return value with null for edu/ucsb/cs156/courses/controllers/ApiController::genericMessage → KILLED |
return Map.of("message", message); |
28 | } | |
29 | ||
30 | @ExceptionHandler({ EntityNotFoundException.class, BadEnrollCdException.class }) | |
31 | @ResponseStatus(HttpStatus.NOT_FOUND) | |
32 | public Object handleGenericException(Throwable e) { | |
33 |
1
1. handleGenericException : replaced return value with null for edu/ucsb/cs156/courses/controllers/ApiController::handleGenericException → KILLED |
return Map.of( |
34 | "type", e.getClass().getSimpleName(), | |
35 | "message", e.getMessage() | |
36 | ); | |
37 | } | |
38 | | |
39 | @ExceptionHandler({IllegalArgumentException.class }) | |
40 | @ResponseStatus(HttpStatus.BAD_REQUEST) | |
41 | public Object handleIllegalArgumentException(Throwable e) { | |
42 |
1
1. handleIllegalArgumentException : replaced return value with null for edu/ucsb/cs156/courses/controllers/ApiController::handleIllegalArgumentException → KILLED |
return Map.of( |
43 | "type", e.getClass().getSimpleName(), | |
44 | "message", e.getMessage() | |
45 | ); | |
46 | } | |
47 | } | |
Mutations | ||
23 |
1.1 |
|
27 |
1.1 |
|
33 |
1.1 |
|
42 |
1.1 |