[MM-57826] Make sure the original errors are wrapped when AppErrors are returned (#26771)
Co-authored-by: Ibrahim Serdar Acikgoz <serdaracikgoz86@gmail.com>
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
423809e0d0
Коммит
8348acac49
@@ -121,14 +121,14 @@ func generateSupportPacket(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
outputDirectoryToUse := OutputDirectory + "_" + model.NewId()
|
||||
err := c.App.CreateZipFileAndAddFiles(fileStorageBackend, fileDatas, outputZipFilename, outputDirectoryToUse)
|
||||
if err != nil {
|
||||
c.Err = model.NewAppError("Api4.generateSupportPacket", "api.unable_to_create_zip_file", nil, err.Error(), http.StatusForbidden)
|
||||
c.Err = model.NewAppError("Api4.generateSupportPacket", "api.unable_to_create_zip_file", nil, "", http.StatusForbidden).Wrap(err)
|
||||
return
|
||||
}
|
||||
|
||||
fileBytes, err := fileStorageBackend.ReadFile(path.Join(outputDirectoryToUse, outputZipFilename))
|
||||
defer fileStorageBackend.RemoveDirectory(outputDirectoryToUse)
|
||||
if err != nil {
|
||||
c.Err = model.NewAppError("Api4.generateSupportPacket", "api.unable_to_read_file_from_backend", nil, err.Error(), http.StatusForbidden)
|
||||
c.Err = model.NewAppError("Api4.generateSupportPacket", "api.unable_to_read_file_from_backend", nil, "", http.StatusForbidden).Wrap(err)
|
||||
return
|
||||
}
|
||||
fileBytesReader := bytes.NewReader(fileBytes)
|
||||
@@ -678,7 +678,7 @@ func pushNotificationAck(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
msg, appError := notificationInterface.GetNotificationMessage(c.AppContext, &ack, c.AppContext.Session().UserId)
|
||||
if appError != nil {
|
||||
c.Err = model.NewAppError("pushNotificationAck", "api.push_notification.id_loaded.fetch.app_error", nil, appError.Error(), http.StatusInternalServerError)
|
||||
c.Err = model.NewAppError("pushNotificationAck", "api.push_notification.id_loaded.fetch.app_error", nil, "", http.StatusInternalServerError).Wrap(appError)
|
||||
return
|
||||
}
|
||||
if err2 := json.NewEncoder(w).Encode(msg); err2 != nil {
|
||||
@@ -688,7 +688,7 @@ func pushNotificationAck(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
return
|
||||
} else if err != nil {
|
||||
c.Err = model.NewAppError("pushNotificationAck", "api.push_notifications_ack.forward.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
c.Err = model.NewAppError("pushNotificationAck", "api.push_notifications_ack.forward.app_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -795,16 +795,16 @@ func upgradeToEnterprise(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
"Path": ipErr.Path,
|
||||
}
|
||||
if ipErr.ErrType == "invalid-user-and-permission" {
|
||||
c.Err = model.NewAppError("upgradeToEnterprise", "api.upgrade_to_enterprise.invalid-user-and-permission.app_error", params, err.Error(), http.StatusForbidden)
|
||||
c.Err = model.NewAppError("upgradeToEnterprise", "api.upgrade_to_enterprise.invalid-user-and-permission.app_error", params, "", http.StatusForbidden).Wrap(err)
|
||||
} else if ipErr.ErrType == "invalid-user" {
|
||||
c.Err = model.NewAppError("upgradeToEnterprise", "api.upgrade_to_enterprise.invalid-user.app_error", params, err.Error(), http.StatusForbidden)
|
||||
c.Err = model.NewAppError("upgradeToEnterprise", "api.upgrade_to_enterprise.invalid-user.app_error", params, "", http.StatusForbidden).Wrap(err)
|
||||
} else if ipErr.ErrType == "invalid-permission" {
|
||||
c.Err = model.NewAppError("upgradeToEnterprise", "api.upgrade_to_enterprise.invalid-permission.app_error", params, err.Error(), http.StatusForbidden)
|
||||
c.Err = model.NewAppError("upgradeToEnterprise", "api.upgrade_to_enterprise.invalid-permission.app_error", params, "", http.StatusForbidden).Wrap(err)
|
||||
}
|
||||
case errors.As(err, &iaErr):
|
||||
c.Err = model.NewAppError("upgradeToEnterprise", "api.upgrade_to_enterprise.system_not_supported.app_error", nil, err.Error(), http.StatusForbidden)
|
||||
c.Err = model.NewAppError("upgradeToEnterprise", "api.upgrade_to_enterprise.system_not_supported.app_error", nil, "", http.StatusForbidden).Wrap(err)
|
||||
default:
|
||||
c.Err = model.NewAppError("upgradeToEnterprise", "api.upgrade_to_enterprise.generic_error.app_error", nil, err.Error(), http.StatusForbidden)
|
||||
c.Err = model.NewAppError("upgradeToEnterprise", "api.upgrade_to_enterprise.generic_error.app_error", nil, "", http.StatusForbidden).Wrap(err)
|
||||
}
|
||||
return
|
||||
}
|
||||
@@ -830,10 +830,10 @@ func upgradeToEnterpriseStatus(c *Context, w http.ResponseWriter, r *http.Reques
|
||||
var isErr *upgrader.InvalidSignature
|
||||
switch {
|
||||
case errors.As(err, &isErr):
|
||||
appErr := model.NewAppError("upgradeToEnterpriseStatus", "api.upgrade_to_enterprise_status.app_error", nil, err.Error(), http.StatusBadRequest)
|
||||
appErr := model.NewAppError("upgradeToEnterpriseStatus", "api.upgrade_to_enterprise_status.app_error", nil, "", http.StatusBadRequest).Wrap(isErr)
|
||||
s = map[string]any{"percentage": 0, "error": appErr.Message}
|
||||
default:
|
||||
appErr := model.NewAppError("upgradeToEnterpriseStatus", "api.upgrade_to_enterprise_status.signature.app_error", nil, err.Error(), http.StatusBadRequest)
|
||||
appErr := model.NewAppError("upgradeToEnterpriseStatus", "api.upgrade_to_enterprise_status.signature.app_error", nil, "", http.StatusBadRequest).Wrap(err)
|
||||
s = map[string]any{"percentage": 0, "error": appErr.Message}
|
||||
}
|
||||
} else {
|
||||
|
||||
Ссылка в новой задаче
Block a user