All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.breuninger.boot.validation.web.GlobalErrorWebExceptionHandler.kt Maven / Gradle / Ivy

There is a newer version: 3.2.1.RELEASE
Show newest version
package com.breuninger.boot.validation.web

import com.breuninger.boot.validation.autoconfiguration.ValidationProperties
import org.springframework.boot.autoconfigure.web.ErrorProperties
import org.springframework.boot.autoconfigure.web.ResourceProperties
import org.springframework.boot.autoconfigure.web.reactive.error.DefaultErrorWebExceptionHandler
import org.springframework.boot.web.reactive.error.ErrorAttributes
import org.springframework.context.ApplicationContext
import org.springframework.http.MediaType
import org.springframework.web.reactive.function.server.ServerRequest
import org.springframework.web.reactive.function.server.ServerResponse
import reactor.core.publisher.Mono

class GlobalErrorWebExceptionHandler(
  private val validationProperties: ValidationProperties,
  errorAttributes: ErrorAttributes,
  resourceProperties: ResourceProperties,
  errorProperties: ErrorProperties,
  applicationContext: ApplicationContext
) : DefaultErrorWebExceptionHandler(errorAttributes, resourceProperties, errorProperties, applicationContext) {

  override fun renderErrorResponse(request: ServerRequest): Mono {
    val errorAttributes = getErrorAttributes(request, isIncludeStackTrace(request, MediaType.ALL))
    val httpStatus = getHttpStatus(errorAttributes)
    return ServerResponse.status(httpStatus)
      .contentType(MediaType.parseMediaType(validationProperties.errorMediaType))
      .syncBody(getWithoutStatus(errorAttributes))
  }

  private fun getWithoutStatus(errorAttributes: Map): Map {
    val withoutStatus = LinkedHashMap(errorAttributes)
    withoutStatus.remove("status")
    return withoutStatus
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy