Files

76 lines
5.1 KiB
HTML

<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml" lang="en"><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/><link rel="stylesheet" href="../jacoco-resources/report.css" type="text/css"/><link rel="shortcut icon" href="../jacoco-resources/report.gif" type="image/gif"/><title>InfrastructureExceptionHandler.java</title><link rel="stylesheet" href="../jacoco-resources/prettify.css" type="text/css"/><script type="text/javascript" src="../jacoco-resources/prettify.js"></script></head><body onload="window['PR_TAB_WIDTH']=4;prettyPrint()"><div class="breadcrumb" id="breadcrumb"><span class="info"><a href="../jacoco-sessions.html" class="el_session">Sessions</a></span><a href="../index.html" class="el_report">bootstrap</a> &gt; <a href="index.source.html" class="el_package">com.project.auth.config.web</a> &gt; <span class="el_source">InfrastructureExceptionHandler.java</span></div><h1>InfrastructureExceptionHandler.java</h1><pre class="source lang-java linenums">package com.project.auth.config.web;
import com.project.auth.application.support.exception.CommonErrorCode;
import com.project.auth.application.support.logging.LogSanitizer;
import com.project.auth.domain.user.exception.DomainException;
import com.project.auth.infrastructure.support.exception.InfrastructureException;
import com.project.auth.presentation.support.exception.ApiErrorHttpStatusMapper;
import com.project.auth.presentation.support.response.ApiResult;
import com.project.auth.presentation.support.response.ApiResultFactory;
import jakarta.servlet.http.HttpServletRequest;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
/**
* InfrastructureErrorCode is kept as an internal classification for logs and alerting.
* Client responses are intentionally normalized to COMMON-999 to avoid exposing internal dependency details.
* This advice stays in bootstrap because moving it to presentation would create a
* presentation -&gt; infrastructure dependency and break the layer rule.
*/
@RestControllerAdvice
@Order(Ordered.HIGHEST_PRECEDENCE)
public class InfrastructureExceptionHandler {
<span class="fc" id="L29"> private static final Logger log = LoggerFactory.getLogger(InfrastructureExceptionHandler.class);</span>
private final ApiResultFactory apiResultFactory;
<span class="fc" id="L33"> public InfrastructureExceptionHandler(ApiResultFactory apiResultFactory) {</span>
<span class="fc" id="L34"> this.apiResultFactory = apiResultFactory;</span>
<span class="fc" id="L35"> }</span>
@ExceptionHandler(InfrastructureException.class)
public ResponseEntity&lt;ApiResult&lt;Void&gt;&gt; handleInfrastructureException(
InfrastructureException exception,
HttpServletRequest request
) {
<span class="fc" id="L42"> log.error(</span>
&quot;Infrastructure failure. errorCode={} method={} requestPath={}&quot;,
<span class="fc" id="L44"> exception.getErrorCode().code(),</span>
<span class="fc" id="L45"> request.getMethod(),</span>
<span class="fc" id="L46"> LogSanitizer.requestPath(request.getRequestURI()),</span>
exception
);
<span class="fc" id="L50"> return ResponseEntity.status(ApiErrorHttpStatusMapper.map(CommonErrorCode.INTERNAL_SERVER_ERROR))</span>
<span class="fc" id="L51"> .body(apiResultFactory.failure(</span>
<span class="fc" id="L52"> CommonErrorCode.INTERNAL_SERVER_ERROR.code(),</span>
<span class="fc" id="L53"> CommonErrorCode.INTERNAL_SERVER_ERROR.message()</span>
));
}
@ExceptionHandler(DomainException.class)
public ResponseEntity&lt;ApiResult&lt;Void&gt;&gt; handleLeakedDomainException(
DomainException exception,
HttpServletRequest request
) {
<span class="fc" id="L62"> log.error(</span>
&quot;Leaked domain exception. method={} requestPath={}&quot;,
<span class="fc" id="L64"> request.getMethod(),</span>
<span class="fc" id="L65"> LogSanitizer.requestPath(request.getRequestURI()),</span>
exception
);
<span class="fc" id="L69"> return ResponseEntity.status(ApiErrorHttpStatusMapper.map(CommonErrorCode.INTERNAL_SERVER_ERROR))</span>
<span class="fc" id="L70"> .body(apiResultFactory.failure(</span>
<span class="fc" id="L71"> CommonErrorCode.INTERNAL_SERVER_ERROR.code(),</span>
<span class="fc" id="L72"> CommonErrorCode.INTERNAL_SERVER_ERROR.message()</span>
));
}
}
</pre><div class="footer"><span class="right">Created with <a href="http://www.jacoco.org/jacoco">JaCoCo</a> 0.8.13.202504020838</span></div></body></html>