mirror of
https://github.com/casdoor/casdoor.git
synced 2025-07-02 11:20:18 +08:00
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:
@ -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
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user