Errors: Remove direct dependencies on github.com/pkg/errors (#64026)

Co-authored-by: Sofia Papagiannaki <1632407+papagian@users.noreply.github.com>
This commit is contained in:
Emil Tullstedt
2023-03-02 16:28:10 +01:00
committed by GitHub
co-authored by Sofia Papagiannaki
parent 8c8f584b41
commit 10ee900beb
10 changed files with 23 additions and 22 deletions
+4 -2
View File
@@ -3,6 +3,7 @@ package api
import (
"bytes"
"encoding/json"
"errors"
"fmt"
"io"
"net/http"
@@ -11,7 +12,6 @@ import (
"strconv"
"strings"
"github.com/pkg/errors"
"gopkg.in/yaml.v3"
"github.com/grafana/grafana/pkg/api/response"
@@ -206,13 +206,15 @@ func messageExtractor(resp *response.NormalResponse) (interface{}, error) {
// ErrorResp creates a response with a visible error
func ErrResp(status int, err error, msg string, args ...interface{}) *response.NormalResponse {
if msg != "" {
err = errors.WithMessagef(err, msg, args...)
formattedMsg := fmt.Sprintf(msg, args...)
err = fmt.Errorf("%s: %w", formattedMsg, err)
}
return response.Error(status, err.Error(), err)
}
// accessForbiddenResp creates a response of forbidden access.
func accessForbiddenResp() response.Response {
//nolint:stylecheck // Grandfathered capitalization of error.
return ErrResp(http.StatusForbidden, errors.New("Permission denied"), "")
}