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:
co-authored by
Sofia Papagiannaki
parent
8c8f584b41
commit
10ee900beb
@@ -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"), "")
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user