| | |
| | | |
| | | import com.vincent.rsf.httpaudit.props.HttpAuditProperties; |
| | | |
| | | import org.springframework.web.context.request.async.AsyncRequestTimeoutException; |
| | | |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import java.net.ConnectException; |
| | | import java.net.SocketTimeoutException; |
| | | import java.nio.charset.Charset; |
| | | import java.nio.charset.StandardCharsets; |
| | | import java.util.concurrent.TimeoutException; |
| | | import java.util.ArrayList; |
| | | import java.util.Comparator; |
| | | import java.util.List; |
| | |
| | | } |
| | | return uri.substring(0, maxLen - 3) + "..."; |
| | | } |
| | | |
| | | /** 无 HTTP 状态码时由异常推断落库状态;超时类为 504 */ |
| | | public static Integer inferHttpStatusFromThrowable(Throwable ex) { |
| | | if (ex == null) { |
| | | return null; |
| | | } |
| | | for (Throwable t = ex; t != null; t = t.getCause()) { |
| | | if (t instanceof SocketTimeoutException || t instanceof TimeoutException) { |
| | | return 504; |
| | | } |
| | | if (t instanceof AsyncRequestTimeoutException) { |
| | | return 504; |
| | | } |
| | | if (t instanceof ConnectException) { |
| | | String m = t.getMessage(); |
| | | if (m != null && m.toLowerCase().contains("timed out")) { |
| | | return 504; |
| | | } |
| | | } |
| | | if ("feign.RetryableException".equals(t.getClass().getName())) { |
| | | Throwable c = t.getCause(); |
| | | if (c instanceof SocketTimeoutException) { |
| | | return 504; |
| | | } |
| | | String m = t.getMessage(); |
| | | if (m != null) { |
| | | String low = m.toLowerCase(); |
| | | if (low.contains("timed out") || low.contains("timeout")) { |
| | | return 504; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | return null; |
| | | } |
| | | } |