package response import ( "errors" "fmt" "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client" sdkstatus "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client/status" "github.com/valyala/fasthttp" "go.uber.org/zap" ) func Error(r *fasthttp.RequestCtx, msg string, code int) { r.Error(msg+"\n", code) } func FormErrorResponse(message string, err error) (int, string, []zap.Field) { var ( msg string statusCode int logFields []zap.Field ) st := new(sdkstatus.ObjectAccessDenied) switch { case errors.As(err, &st): statusCode = fasthttp.StatusForbidden reason := st.Reason() msg = fmt.Sprintf("%s: %v: %s", message, err, reason) logFields = append(logFields, zap.String("error_detail", reason)) case client.IsErrObjectNotFound(err) || client.IsErrContainerNotFound(err): statusCode = fasthttp.StatusNotFound msg = "Not Found" default: statusCode = fasthttp.StatusBadRequest msg = fmt.Sprintf("%s: %v", message, err) } return statusCode, msg, logFields }