Skip to content

currenjin/exceptor

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Exceptor

🚨 A simple exception handler

Simple Usage

@RestController
@Exceptor(status = HttpStatus.BAD_REQUEST, exception = IllegalArgumentException.class)
public class ExampleController {

    @GetMapping("/example")
    ResponseEntity<String> request() {
        ...
    }
}

Test

@SpringBootTest
@AutoConfigureMockMvc
class ExampleAfterControllerTest {

    @Autowired
    MockMvc mvc;

    @Test
    void _400_bad_request() throws Exception {
        mvc.perform(get("/example/after"))
                .andExpect(status().isBadRequest())
                .andExpect(jsonPath("reason").value("test"))
                .andExpect(jsonPath("httpCode").value(400));
    }
}