/
grpcstatuserr.go
42 lines (30 loc) · 1.26 KB
/
grpcstatuserr.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package common
import (
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
"github.com/cloud-barista/poc-cicd-tumblebug/src/api/grpc/logger"
)
// ===== [ Constants and Variables ] =====
// ===== [ Types ] =====
// ===== [ Implementations ] =====
// ===== [ Private Functions ] =====
// ===== [ Public Functions ] =====
// ConvGrpcStatusErr - GRPC 상태 코드 에러로 변환
func ConvGrpcStatusErr(err error, tag string, method string) error {
logger := logger.NewLogger()
if err != nil {
if errStatus, ok := status.FromError(err); ok {
logger.Error(tag, " error while calling ", method, " method: ", errStatus.Message())
return status.Errorf(errStatus.Code(), "%s error while calling %s method: %v ", tag, method, errStatus.Message())
}
logger.Error(tag, " error while calling ", method, " method: ", err)
return status.Errorf(codes.Internal, "%s error while calling %s method: %v ", tag, method, err)
}
return nil
}
// NewGrpcStatusErr - GRPC 상태 코드 에러 생성
func NewGrpcStatusErr(msg string, tag string, method string) error {
logger := logger.NewLogger()
logger.Error(tag, " error while calling ", method, " method: ", msg)
return status.Errorf(codes.Internal, "%s error while calling %s method: %s ", tag, method, msg)
}