fix(t231): expose freight preflight errors
This commit is contained in:
@@ -845,6 +845,18 @@ func writeUsecaseError(ctx *gin.Context, err error) {
|
||||
case usecase.ErrorKindUnavailable:
|
||||
status = http.StatusServiceUnavailable
|
||||
}
|
||||
switch typed.Code {
|
||||
case "ERP_NOT_CONFIGURED", "ERP_LOGIN_REJECTED":
|
||||
status = http.StatusUnprocessableEntity
|
||||
case "ERP_RESPONSE_INVALID":
|
||||
status = http.StatusBadGateway
|
||||
case "OCR_SERVICE_INVALID", "ERP_UNAVAILABLE":
|
||||
status = http.StatusServiceUnavailable
|
||||
}
|
||||
message := typed.Message
|
||||
if preflightMessage, ok := freightPreflightPublicMessage(typed.Code); ok {
|
||||
message = preflightMessage
|
||||
}
|
||||
details := gin.H{}
|
||||
if len(typed.Fields) > 0 {
|
||||
details["fields"] = typed.Fields
|
||||
@@ -853,12 +865,29 @@ func writeUsecaseError(ctx *gin.Context, err error) {
|
||||
ctx,
|
||||
status,
|
||||
typed.Code,
|
||||
typed.Message,
|
||||
message,
|
||||
typed.Retryable,
|
||||
details,
|
||||
)
|
||||
}
|
||||
|
||||
func freightPreflightPublicMessage(code string) (string, bool) {
|
||||
switch code {
|
||||
case "ERP_NOT_CONFIGURED":
|
||||
return "ERP credentials are not configured", true
|
||||
case "ERP_LOGIN_REJECTED":
|
||||
return "ERP login was rejected", true
|
||||
case "ERP_RESPONSE_INVALID":
|
||||
return "ERP response is invalid", true
|
||||
case "OCR_SERVICE_INVALID":
|
||||
return "OCR service is invalid", true
|
||||
case "ERP_UNAVAILABLE":
|
||||
return "ERP is temporarily unavailable", true
|
||||
default:
|
||||
return "", false
|
||||
}
|
||||
}
|
||||
|
||||
func writePublicError(
|
||||
ctx *gin.Context,
|
||||
status int,
|
||||
|
||||
Reference in New Issue
Block a user