mirror of
https://github.com/SigNoz/signoz.git
synced 2026-06-19 06:50:24 +01:00
Some checks failed
build-staging / js-build (push) Has been cancelled
build-staging / prepare (push) Has been cancelled
build-staging / go-build (push) Has been cancelled
build-staging / staging (push) Has been cancelled
Release Drafter / update_release_draft (push) Has been cancelled
* feat: extend error responses with new error struct
* fix: enriched error for dashboard api
* fix: merge issues
* fix: reverted dashboards changes and add for cloud integrations
* fix: delete file
* fix: add back file
* fix: added a helper
* fix: removed invlaid referencess
* fix: generate openapi
* fix: keeping additional along with suggestion
* Revert "fix: keeping additional along with suggestion"
This reverts commit be30e2ffd2.
* fix: added suggestions per additonal error
* fix: generate openapi
* fix: remove valid references
* fix: removeg valid references for select and group by and only did you mean is kept
* fix: unit test
* fix: use binding for deconding for both ee and community
* fix: trim down suggestions methods
* fix: added renamed methods and moved stuff around
* fix: typo
* fix: removed json decoder
* fix: added empty check
* fix: retain addtional
* fix: reverted re-structing of file
78 lines
1.9 KiB
Go
78 lines
1.9 KiB
Go
package errors
|
|
|
|
import (
|
|
"encoding/json"
|
|
"net/url"
|
|
"time"
|
|
)
|
|
|
|
type JSON struct {
|
|
Type string `json:"type,omitempty"`
|
|
Code string `json:"code" required:"true"`
|
|
Message string `json:"message" required:"true"`
|
|
Url string `json:"url,omitempty"`
|
|
Errors []responseerroradditional `json:"errors,omitempty"`
|
|
Retry *responseretryjson `json:"retry,omitempty"`
|
|
Suggestions []string `json:"suggestions,omitempty"`
|
|
}
|
|
|
|
type responseretryjson struct {
|
|
Delay time.Duration `json:"delay"`
|
|
}
|
|
|
|
type responseerroradditional struct {
|
|
Message string `json:"message,omitempty"`
|
|
Suggestions []string `json:"suggestions,omitempty"`
|
|
}
|
|
|
|
func AsJSON(cause error) *JSON {
|
|
// See if this is an instance of the base error or not
|
|
t, c, m, _, u, a := Unwrapb(cause)
|
|
|
|
rea := make([]responseerroradditional, len(a))
|
|
for k, v := range a {
|
|
rea[k] = responseerroradditional{Message: v.message, Suggestions: v.suggestions}
|
|
}
|
|
|
|
var retry *responseretryjson
|
|
if r := retryOf(cause); r != nil {
|
|
retry = &responseretryjson{Delay: r.delay}
|
|
}
|
|
|
|
return &JSON{
|
|
Type: t.String(),
|
|
Code: c.String(),
|
|
Message: m,
|
|
Url: u,
|
|
Errors: rea,
|
|
Retry: retry,
|
|
Suggestions: suggestionsOf(cause),
|
|
}
|
|
}
|
|
|
|
func AsURLValues(cause error) url.Values {
|
|
// See if this is an instance of the base error or not
|
|
_, c, m, _, u, a := Unwrapb(cause)
|
|
|
|
rea := make([]responseerroradditional, len(a))
|
|
for k, v := range a {
|
|
rea[k] = responseerroradditional{Message: v.message, Suggestions: v.suggestions}
|
|
}
|
|
|
|
errors, err := json.Marshal(rea)
|
|
if err != nil {
|
|
return url.Values{
|
|
"code": {c.String()},
|
|
"message": {m},
|
|
"url": {u},
|
|
}
|
|
}
|
|
|
|
return url.Values{
|
|
"code": {c.String()},
|
|
"message": {m},
|
|
"url": {u},
|
|
"errors": {string(errors)},
|
|
}
|
|
}
|