mirror of
https://github.com/CJackHwang/ds2api.git
synced 2026-05-14 21:25:09 +08:00
refactor backend API structure
This commit is contained in:
31
internal/httpapi/admin/shared/request_error.go
Normal file
31
internal/httpapi/admin/shared/request_error.go
Normal file
@@ -0,0 +1,31 @@
|
||||
package shared
|
||||
|
||||
import "errors"
|
||||
|
||||
type requestError struct {
|
||||
detail string
|
||||
}
|
||||
|
||||
func (e *requestError) Error() string {
|
||||
return e.detail
|
||||
}
|
||||
|
||||
func newRequestError(detail string) error {
|
||||
return &requestError{detail: detail}
|
||||
}
|
||||
|
||||
func NewRequestError(detail string) error {
|
||||
return newRequestError(detail)
|
||||
}
|
||||
|
||||
func requestErrorDetail(err error) (string, bool) {
|
||||
var reqErr *requestError
|
||||
if errors.As(err, &reqErr) {
|
||||
return reqErr.detail, true
|
||||
}
|
||||
return "", false
|
||||
}
|
||||
|
||||
func RequestErrorDetail(err error) (string, bool) {
|
||||
return requestErrorDetail(err)
|
||||
}
|
||||
Reference in New Issue
Block a user