123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210 |
- package gerror
- import (
- "runtime"
- "strings"
- "github.com/gin-gonic/gin"
- )
- type GCODE int
- //ANCHOR temporary error code
- const (
- OK = 100
- //health check
- HEALTHY = 110
- //mysqlError
- InvalidConnection = 200
- NotFoundRecord = 201
- TooManyConnection = 203
- MysqlTimeout = 204
- MysqlContextError = 205
- MysqlSaveError = 206
- CouldNotAppendRow = 207
- //redis
- RedisError = 220
- NotMatchedValueError = 221
- //go
- Error3rdParty = 250
- GoContextError = 251
- MultipartError = 252
- FileUploadError = 253
- // Error3rdParty중에서 iamport
- IamPortImpUIDNotFound = 270
- IamPortUnauthorized = 271
- // Error3rdParty중에서 SweetTracker
- SweetTrackerNotDelivered = 280
- //badRequest
- UnsupportedFileFormat = 300
- InvalidParameterValue = 301
- InvalidParameterType = 302
- DuplicateValue = 303
- //authorized
- Unauthorized = 400
- MakeSessionError = 401
- GetSNSUserInfoError = 402
- LoginFailed = 403
- NotViralUser = 404
- PermissionNotFound = 405
- //brand
- NotVerifyError = 500
- //order
- ProductOptionStockError = 520
- TimesaleOptionStockError = 521
- IamPortError = 522
- UnVerifiedPayment = 523
- UndeliverableArea = 524
- ShippingPolicyCountOver = 525
- NotYet = 526
- //feed
- AlreadyReported = 550
- FeedUnauthorizedUser = 551
- //point
- PointRegisterError = 570
- PointDeletedError = 571
- //viral point
- OverflowRequestAmount = 580
- ViralPointRegisterError = 581
- // certification
- DuplicateCertificationUID = 600
- NotMatchPhone = 601
- NoCertificationHistory = 602
- // viral_user
- AlreadyExisted = 650
- //blockchain
- BlockChainError = 700
- NotHaveUserWallet = 701
- NotEnoughLeftBalance = 702
- FailToSweep = 703
- // http error
- HttpRequestWentWrong = 800
- //Log error
- LogTrackingError = 900
- //common
- NothingToProcess = 5000 // 처리할 데이터가 없을 경우 사용하는 일반적인 에러
- )
- var statusText = map[GCODE]string{
- OK: "OK",
- HEALTHY: "Calm down, I'm helathy",
- InvalidConnection: "Invalid connection",
- NotFoundRecord: "Could not found matched record",
- TooManyConnection: "Too many connection(Count overflow)",
- MysqlTimeout: "mysql lock wait timeout",
- MysqlContextError: "mysql context error",
- MysqlSaveError: "Error while saving",
- CouldNotAppendRow: "Cannot append a row ",
- RedisError: "Record Error(Redis)",
- NotMatchedValueError: "Mismatch in phone between Redis,RDB",
- Error3rdParty: "Error occurred 3rd party service",
- GoContextError: "Error occurred at go",
- MultipartError: "multipart error",
- FileUploadError: "Error occurred during file upload",
- IamPortImpUIDNotFound: "IamPort data not found from imp_uid",
- IamPortUnauthorized: "IamPort accetoken invalid",
- SweetTrackerNotDelivered: "SweetTracker response not delivered",
- UnsupportedFileFormat: "Unsupported file format",
- InvalidParameterValue: "Invalid parameter value",
- InvalidParameterType: "Invalid parameter's type",
- DuplicateValue: "Duplicate value",
- PermissionNotFound: "Permission not found",
- Unauthorized: "Unauthorized request",
- MakeSessionError: "Error occurred during make session",
- GetSNSUserInfoError: "Get SNS user information error",
- NotVerifyError: "Not Verify Error",
- LoginFailed: "Fail to login",
- NotViralUser: "Authorized but, not viral_user",
- ProductOptionStockError: "Product option stock error",
- TimesaleOptionStockError: "Timesale option stock error",
- IamPortError: "Iamport Error",
- UnVerifiedPayment: "Unverified payment",
- UndeliverableArea: "Undeliverable Area",
- ShippingPolicyCountOver: "Over Shipping policy count",
- NotYet: "It's not the right time. Can't be completed because of date",
- AlreadyReported: "Already Reported",
- FeedUnauthorizedUser: "Feed Unauthorized User",
- PointRegisterError: "Point Register Error",
- PointDeletedError: "Point Delete Error",
- OverflowRequestAmount: "The request amount is bigger than I had.",
- ViralPointRegisterError: "Viral Point Register Error",
- DuplicateCertificationUID: "Already exist certification row in database",
- NotMatchPhone: "Not match phone between user_phone, certification_phone",
- NoCertificationHistory: "When convert common_user to viral_user, there is no certification_phone history",
- AlreadyExisted: "Already exist viral_user",
- BlockChainError: "BlockChain Error",
- NotHaveUserWallet: "Doesn't have any user wallet",
- NotEnoughLeftBalance: "Not enough left balance.",
- FailToSweep: "Fail to sweep",
- HttpRequestWentWrong: "Http Request Went Wrong Some reasone",
- LogTrackingError: "Error in tracking and storing logs.",
- NothingToProcess: "There is nothing to process.",
- }
- func convertGcodeToText(code GCODE) string {
- return statusText[code]
- }
- func traceFunctionName() string {
- pc, _, _, _ := runtime.Caller(2)
- fulllName := runtime.FuncForPC(pc).Name()
- funcName := strings.Split(fulllName, ".")
- return funcName[len(funcName)-1]
- }
- func IntegratedResponseToRequest(c *gin.Context, statusCode int, gcode GCODE, data interface{}, err error) {
- if statusCode == 200 {
- if data == nil {
- c.Status(statusCode)
- return
- }
- c.JSON(statusCode, data)
- return
- } else {
- c.JSON(statusCode, gin.H{
- "payload": data,
- "gcode": gcode,
- "gcode_message": convertGcodeToText(gcode),
- "excute_function": traceFunctionName(),
- "error": err,
- })
- return
- }
- }
|