Config UI: add provider auth subject to login errors (#25342)

This commit is contained in:
andig 2025-11-20 19:02:18 +01:00 • committed by GitHub
parent 5aadb01eae
commit 1f0bd92518
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 58 additions and 32 deletions

36
util/error.go Normal file
View file

@ -0,0 +1,36 @@
package util
import (
"errors"
"github.com/evcc-io/evcc/api"
"go.yaml.in/yaml/v4"
)
// ErrorAsJson returns an error as json-formattable struct
func ErrorAsJson(err error) any {
res := struct {
Error string `json:"error"`
Line int `json:"line,omitempty"`
LoginRequired string `json:"loginRequired,omitempty"`
}{
Error: err.Error(),
}
if ae := new(api.ErrLoginRequired); errors.As(err, &ae) {
res.LoginRequired = ae.ProviderAuth
}
var (
ype *yaml.ParserError
yue *yaml.UnmarshalError
)
switch {
case errors.As(err, &ype):
res.Line = ype.Line
case errors.As(err, &yue):
res.Line = yue.Line
}
return res
}