penambahan All case Satu sehat
This commit is contained in:
@@ -247,7 +247,9 @@ func handleErrors(c *gin.Context, err error, cfg *ErrorMiddlewareConfig) {
|
||||
response := createErrorResponse(c, appErr, cfg)
|
||||
|
||||
// Send response
|
||||
c.JSON(appErr.HTTPStatus(), response)
|
||||
if !c.Writer.Written() {
|
||||
c.JSON(appErr.HTTPStatus(), response)
|
||||
}
|
||||
}
|
||||
|
||||
// createErrorResponse creates error response
|
||||
@@ -255,18 +257,30 @@ func createErrorResponse(c *gin.Context, err Error, cfg *ErrorMiddlewareConfig)
|
||||
lang := c.GetString("language")
|
||||
requestID := c.GetString("request_id")
|
||||
|
||||
details := err.Metadata()
|
||||
if details == nil {
|
||||
details = make(map[string]interface{})
|
||||
}
|
||||
|
||||
timestamp := time.Now().UTC().Format(time.RFC3339)
|
||||
if ts, ok := details["timestamp"].(string); ok {
|
||||
timestamp = ts
|
||||
}
|
||||
|
||||
response := gin.H{
|
||||
"status": "error",
|
||||
"error": gin.H{
|
||||
"code": err.Code(),
|
||||
"message": err.GetLocalizedMessage(lang),
|
||||
"details": err.Metadata(),
|
||||
"request_id": requestID,
|
||||
"timestamp": time.Now().UTC().Format(time.RFC3339),
|
||||
"retryable": IsRetryable(err.Code()),
|
||||
"code": err.Code(),
|
||||
"details": details,
|
||||
"message": err.GetLocalizedMessage(lang),
|
||||
"request_id": requestID,
|
||||
"retryable": IsRetryable(err.Code()),
|
||||
"stack_trace": nil,
|
||||
"timestamp": timestamp,
|
||||
},
|
||||
"meta": gin.H{
|
||||
"http_status": err.HTTPStatus(),
|
||||
"category": err.Category(),
|
||||
"http_status": err.HTTPStatus(),
|
||||
},
|
||||
}
|
||||
|
||||
@@ -302,13 +316,16 @@ func ValidationHandler(c *gin.Context, err error) {
|
||||
if appErr.Category() == CategoryValidation {
|
||||
if details, ok := appErr.Metadata()["validation_errors"]; ok {
|
||||
response := gin.H{
|
||||
"status": "error",
|
||||
"error": gin.H{
|
||||
"code": appErr.Code(),
|
||||
"message": appErr.GetLocalizedMessage(getLanguageFromContext(c)),
|
||||
"fields": details,
|
||||
},
|
||||
}
|
||||
c.JSON(http.StatusBadRequest, response)
|
||||
if !c.Writer.Written() {
|
||||
c.JSON(http.StatusBadRequest, response)
|
||||
}
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user