@@ -5,10 +5,11 @@ import org.springframework.http.ResponseEntity
5
5
import org.springframework.web.bind.annotation.ExceptionHandler
6
6
import org.springframework.web.bind.annotation.RestControllerAdvice
7
7
import ru.ifmo.se.dating.api.GeneralErrorMessage
8
- import ru.ifmo.se.dating.exception.AuthenticationException
9
8
import ru.ifmo.se.dating.exception.GenericException
10
9
import ru.ifmo.se.dating.exception.InvalidValueException
11
10
import ru.ifmo.se.dating.exception.NotFoundException
11
+ import ru.ifmo.se.dating.exception.ConflictException
12
+ import ru.ifmo.se.dating.exception.AuthenticationException
12
13
13
14
interface SpringExceptionMapping {
14
15
fun httpCode (exception : GenericException ): HttpStatus ?
@@ -31,17 +32,18 @@ interface SpringDomainExceptionMapping<T : GenericException> : SpringExceptionMa
31
32
class SpringGenericExceptionHandler (private val mapping : SpringExceptionMapping ) {
32
33
val GenericException .httpCode: HttpStatus
33
34
get() = mapping.httpCode(this ) ? : when (this ) {
35
+ is AuthenticationException -> HttpStatus .UNAUTHORIZED
36
+ is ConflictException -> HttpStatus .CONFLICT
34
37
is InvalidValueException -> HttpStatus .BAD_REQUEST
35
38
is NotFoundException -> HttpStatus .NOT_FOUND
36
- is AuthenticationException -> HttpStatus .UNAUTHORIZED
37
39
else -> throw NotImplementedError (" $this " )
38
40
}
39
41
40
42
@ExceptionHandler(GenericException ::class )
41
43
fun handle (exception : GenericException ) =
42
44
exception.toResponseEntity()
43
45
44
- fun GenericException.toResponseEntity () =
46
+ fun GenericException.toResponseEntity (): ResponseEntity < GeneralErrorMessage > =
45
47
ResponseEntity
46
48
.status(this .httpCode)
47
49
.body(
0 commit comments