-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathProblemAdviceTrait.java
More file actions
44 lines (40 loc) · 1.31 KB
/
ProblemAdviceTrait.java
File metadata and controls
44 lines (40 loc) · 1.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package com.ksoot.problem.spring.advice.general;
import com.ksoot.problem.core.DefaultProblem;
import com.ksoot.problem.core.Problem;
import com.ksoot.problem.core.ThrowableProblem;
import com.ksoot.problem.spring.advice.AdviceTrait;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ExceptionHandler;
/**
* Advice trait to handle {@link ThrowableProblem}s and {@link DefaultProblem}s.
*
* @param <T> the request type
* @param <R> the response type
* @see Problem
* @see ThrowableProblem
* @see DefaultProblem
*/
public interface ProblemAdviceTrait<T, R> extends AdviceTrait<T, R> {
/**
* Handles {@link ThrowableProblem} and converts it into a response.
*
* @param problem the problem
* @param request the request
* @return the error response
*/
@ExceptionHandler
default R handleProblem(final ThrowableProblem problem, final T request) {
return toResponse(problem, request);
}
/**
* Handles {@link DefaultProblem} and converts it into a response.
*
* @param problem the default problem
* @param request the request
* @return the error response
*/
@ExceptionHandler
default R handleProblem(final DefaultProblem problem, final T request) {
return toResponse(problem, request, HttpStatus.INTERNAL_SERVER_ERROR, problem);
}
}