feat: return most backend API errors to frontend (#1836)

* feat: return most backend API errros to frontend

Signed-off-by: yehong <239859435@qq.com>

* refactor: reduce int type change

Signed-off-by: yehong <239859435@qq.com>

* feat: return err backend in token.go

Signed-off-by: yehong <239859435@qq.com>

---------

Signed-off-by: yehong <239859435@qq.com>
This commit is contained in:
yehong
2023-05-30 15:49:39 +08:00
committed by GitHub
parent 34151c0095
commit 02e692a300
105 changed files with 3788 additions and 1734 deletions

View File

@ -26,11 +26,7 @@ import (
var logPostOnly bool
func init() {
var err error
logPostOnly, err = conf.GetConfigBool("logPostOnly")
if err != nil {
// panic(err)
}
logPostOnly = conf.GetConfigBool("logPostOnly")
}
type Record struct {
@ -108,49 +104,48 @@ func AddRecord(record *Record) bool {
return affected != 0
}
func GetRecordCount(field, value string, filterRecord *Record) int {
func GetRecordCount(field, value string, filterRecord *Record) (int64, error) {
session := GetSession("", -1, -1, field, value, "", "")
count, err := session.Count(filterRecord)
if err != nil {
panic(err)
}
return int(count)
return session.Count(filterRecord)
}
func GetRecords() []*Record {
func GetRecords() ([]*Record, error) {
records := []*Record{}
err := adapter.Engine.Desc("id").Find(&records)
if err != nil {
panic(err)
return records, err
}
return records
return records, nil
}
func GetPaginationRecords(offset, limit int, field, value, sortField, sortOrder string, filterRecord *Record) []*Record {
func GetPaginationRecords(offset, limit int, field, value, sortField, sortOrder string, filterRecord *Record) ([]*Record, error) {
records := []*Record{}
session := GetSession("", offset, limit, field, value, sortField, sortOrder)
err := session.Find(&records, filterRecord)
if err != nil {
panic(err)
return records, err
}
return records
return records, nil
}
func GetRecordsByField(record *Record) []*Record {
func GetRecordsByField(record *Record) ([]*Record, error) {
records := []*Record{}
err := adapter.Engine.Find(&records, record)
if err != nil {
panic(err)
return records, err
}
return records
return records, nil
}
func SendWebhooks(record *Record) error {
webhooks := getWebhooksByOrganization(record.Organization)
webhooks, err := getWebhooksByOrganization(record.Organization)
if err != nil {
return err
}
for _, webhook := range webhooks {
if !webhook.IsEnabled {
continue
@ -166,7 +161,11 @@ func SendWebhooks(record *Record) error {
if matched {
if webhook.IsUserExtended {
user := GetMaskedUser(getUser(record.Organization, record.User))
user, err := GetMaskedUser(getUser(record.Organization, record.User))
if err != nil {
return err
}
record.ExtendedUser = user
}