Added httpHeaders in ExceptionHandlerAdvice

This commit is contained in:
Denis Kazantsev 2022-03-30 11:09:36 +03:00
parent 345db02feb
commit fb8afe2b14
1 changed files with 7 additions and 1 deletions

View File

@ -1,5 +1,6 @@
package ru.touchin.exception.handler.spring.advices
import org.springframework.http.HttpHeaders
import org.springframework.http.ResponseEntity
import org.springframework.web.bind.annotation.ExceptionHandler
import org.springframework.web.bind.annotation.RestControllerAdvice
@ -30,7 +31,12 @@ class ExceptionHandlerAdvice(
val body = exceptionResponseBodyCreator(result.apiError)
return ResponseEntity(body, result.status)
val headers = HttpHeaders().apply {
set("X-Error-Code", result.apiError.errorCode.toString())
set("X-Error-Message", result.apiError.errorMessage)
}
return ResponseEntity(body, headers, result.status)
}
}