package Ġcom . yun ik ov . api . errors Ċ Ċ import Ġcom . fasterxml . jackson . databind . ObjectMapper Ċ import Ġorg . springframework . core . io . buffer . Data Buffer Utils Ċ import Ġorg . springframework . http . HttpHeaders Ċ import Ġorg . springframework . http . HttpStatus Ċ import Ġorg . springframework . http . MediaType Ċ import Ġorg . springframework . web . server . Server Web Exchange Ċ import Ġreactor . core . publisher . Mono Ċ import Ġjava . nio . charset . Charset Ċ Ċ abstract Ġclass ĠHttp ErrorHandler ( private Ġval ĠobjectMapper : ĠObjectMapper ) Ġ{ ĊĊĠĠĠ Ġfun Ġhandle ( server Web Exchange : ĠServer Web Exchange , ĠerrorCode : ĠInt , Ġhttp Status : ĠHttpStatus ): ĠMono < Void > Ġ{ ĊĠĠĠĠĠĠĠ Ġreturn Ġhandle ( server Web Exchange , ĠError Response ( errorCode , Ġhttp Status . reason Phrase , Ġhttp Status )) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġfun Ġhandle ( exchange : ĠServer Web Exchange , Ġerror Response : ĠError Response ): ĠMono < Void > Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġresponse Ġ= Ġexchange . response ĊĠĠĠĠĠĠĠ Ġresponse . headers . set ( HttpHeaders . CONTENT _ TYPE , ĠMediaType . APPLICATION _ JSON _ UTF 8 _ VALUE ) ĊĠĠĠĠĠĠĠ Ġresponse . statusCode Ġ= Ġerror Response . http Status ĊĊĠĠĠĠĠĠĠ Ġval Ġerror Json Ġ= ĠobjectMapper . writeValue AsString ( error Response ) ĊĠĠĠĠĠĠĠ Ġval Ġdata Buffer Factory Ġ= Ġresponse . buffer Factory () ĊĠĠĠĠĠĠĠ Ġval Ġbuffer Ġ= Ġdata Buffer Factory . wrap ( error Json . toByteArray ( Charset . default Charset ())) ĊĊĠĠĠĠĠĠĠ Ġreturn Ġresponse . write With ( Mono . just ( buffer )). do OnError Ġ{ ĠData Buffer Utils . release ( buffer ) Ġ} ĊĠĠĠ Ġ} Ċ }