feat: closes #39
This commit is contained in:
@@ -387,6 +387,14 @@ func (c Context) ErrorCode(err error, code int, data AnyMap) *Error {
|
||||
return &Error{code, nil, c.AddMap(data)}
|
||||
}
|
||||
|
||||
func (c Context) UnsafeErrorCode(err error, code int, data AnyMap) *Error {
|
||||
if err != nil {
|
||||
c.Logger.Errorf("Something went wrong returning with: %d\n.Err:\n", code)
|
||||
c.Logger.Error(err)
|
||||
}
|
||||
return &Error{code, nil, c.AddMap(data)}
|
||||
}
|
||||
|
||||
func (c Context) Error500(err error) *Error {
|
||||
return c.ErrorCode(err, http.StatusInternalServerError, nil)
|
||||
}
|
||||
@@ -414,6 +422,12 @@ func (x Handle) createContext(handler *Handle, mode AnswerType, r *http.Request)
|
||||
|
||||
var token *string
|
||||
|
||||
logger := log.NewWithOptions(os.Stdout, log.Options{
|
||||
ReportTimestamp: true,
|
||||
TimeFormat: time.Kitchen,
|
||||
Prefix: r.URL.Path,
|
||||
})
|
||||
|
||||
for _, r := range r.Cookies() {
|
||||
if r.Name == "auth" {
|
||||
token = &r.Value
|
||||
@@ -425,6 +439,8 @@ func (x Handle) createContext(handler *Handle, mode AnswerType, r *http.Request)
|
||||
if token == nil {
|
||||
return &Context{
|
||||
Mode: mode,
|
||||
Logger: logger,
|
||||
Db: handler.Db,
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -433,12 +449,6 @@ func (x Handle) createContext(handler *Handle, mode AnswerType, r *http.Request)
|
||||
return nil, errors.Join(err, LogoffError)
|
||||
}
|
||||
|
||||
logger := log.NewWithOptions(os.Stdout, log.Options{
|
||||
ReportTimestamp: true,
|
||||
TimeFormat: time.Kitchen,
|
||||
Prefix: r.URL.Path,
|
||||
})
|
||||
|
||||
return &Context{token, user, mode, logger, handler.Db}, nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user