Config UI: add provider auth subject to login errors (#25342)
This commit is contained in:
parent
5aadb01eae
commit
1f0bd92518
6 changed files with 58 additions and 32 deletions
36
util/error.go
Normal file
36
util/error.go
Normal 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
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue