1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package com.linecorp.centraldogma.server.internal.thrift;
18
19 import java.util.function.Function;
20
21 import org.slf4j.Logger;
22 import org.slf4j.LoggerFactory;
23
24 import com.linecorp.armeria.common.RequestContext;
25 import com.linecorp.centraldogma.internal.thrift.CentralDogmaException;
26 import com.linecorp.centraldogma.internal.thrift.ErrorCode;
27
28 final class CentralDogmaExceptions {
29
30 private static final Logger logger = LoggerFactory.getLogger(CentralDogmaExceptions.class);
31
32 static void log(String operationName, CentralDogmaException e) {
33 final RequestContext ctx =
34 RequestContext.mapCurrent(Function.identity(), () -> null);
35
36 final ErrorCode errorCode = e.getErrorCode();
37 switch (errorCode) {
38 case BAD_REQUEST:
39 case PROJECT_NOT_FOUND:
40 case PROJECT_EXISTS:
41 case REPOSITORY_NOT_FOUND:
42 case REPOSITORY_EXISTS:
43 case REVISION_NOT_FOUND:
44 case REVISION_EXISTS:
45 case ENTRY_NOT_FOUND:
46 case CHANGE_CONFLICT:
47 case QUERY_FAILURE:
48 if (logger.isDebugEnabled()) {
49 if (ctx != null) {
50 logger.debug("{} Exception with error code {} ({}) from: {}()",
51 ctx, errorCode, errorCode.getValue(), operationName, e);
52 } else {
53 logger.debug("Exception with error code {} ({}) from: {}()",
54 errorCode, errorCode.getValue(), operationName, e);
55 }
56 }
57 break;
58 case REDUNDANT_CHANGE:
59 case SHUTTING_DOWN:
60
61
62 if (logger.isDebugEnabled()) {
63 if (ctx != null) {
64 logger.debug("{} Exception with error code {} ({}) from: {}()",
65 ctx, errorCode, errorCode.getValue(), operationName);
66 } else {
67 logger.debug("Exception with error code {} ({}) from: {}()",
68 errorCode, errorCode.getValue(), operationName);
69 }
70 }
71 break;
72 default:
73 if (ctx != null) {
74 logger.warn("{} Unexpected exception with error code {} ({}) from: {}()",
75 ctx, errorCode, errorCode.getValue(), operationName, e);
76 } else {
77 logger.warn("Unexpected exception with error code {} ({}) from: {}()",
78 errorCode, errorCode.getValue(), operationName, e);
79 }
80 }
81 }
82
83 private CentralDogmaExceptions() {}
84 }