Fix indentation after errors.AsType refactor
Signed-off-by: Émile Ré <emile@probo.com>
This commit is contained in:
@@ -62,31 +62,31 @@ func NewAPIKeyMiddleware(svc *iam.Service, tokenSecret string) func(next http.Ha
|
||||
return
|
||||
}
|
||||
|
||||
apiKey, err := svc.APIKeyService.GetAPIKey(ctx, keyID)
|
||||
if err != nil {
|
||||
if _, ok := errors.AsType[*iam.ErrPersonalAPIKeyNotFound](err); ok {
|
||||
next.ServeHTTP(w, r)
|
||||
return
|
||||
apiKey, err := svc.APIKeyService.GetAPIKey(ctx, keyID)
|
||||
if err != nil {
|
||||
if _, ok := errors.AsType[*iam.ErrPersonalAPIKeyNotFound](err); ok {
|
||||
next.ServeHTTP(w, r)
|
||||
return
|
||||
}
|
||||
|
||||
if _, ok := errors.AsType[*iam.ErrPersonalAPIKeyExpired](err); ok {
|
||||
next.ServeHTTP(w, r)
|
||||
return
|
||||
}
|
||||
|
||||
panic(fmt.Errorf("cannot get personal API key: %w", err))
|
||||
}
|
||||
|
||||
if _, ok := errors.AsType[*iam.ErrPersonalAPIKeyExpired](err); ok {
|
||||
next.ServeHTTP(w, r)
|
||||
return
|
||||
identity, err := svc.AccountService.GetIdentity(ctx, apiKey.IdentityID)
|
||||
if err != nil {
|
||||
if _, ok := errors.AsType[*iam.ErrIdentityNotFound](err); ok {
|
||||
next.ServeHTTP(w, r)
|
||||
return
|
||||
}
|
||||
|
||||
panic(fmt.Errorf("cannot get identity: %w", err))
|
||||
}
|
||||
|
||||
panic(fmt.Errorf("cannot get personal API key: %w", err))
|
||||
}
|
||||
|
||||
identity, err := svc.AccountService.GetIdentity(ctx, apiKey.IdentityID)
|
||||
if err != nil {
|
||||
if _, ok := errors.AsType[*iam.ErrIdentityNotFound](err); ok {
|
||||
next.ServeHTTP(w, r)
|
||||
return
|
||||
}
|
||||
|
||||
panic(fmt.Errorf("cannot get identity: %w", err))
|
||||
}
|
||||
|
||||
ctx = ContextWithAPIKey(ctx, apiKey)
|
||||
ctx = ContextWithIdentity(ctx, identity)
|
||||
|
||||
|
||||
@@ -65,37 +65,37 @@ func NewSessionMiddleware(svc *iam.Service, cookieConfig securecookie.Config) fu
|
||||
return
|
||||
}
|
||||
|
||||
session, err := svc.SessionService.GetSession(ctx, sessionID)
|
||||
if err != nil {
|
||||
if _, ok := errors.AsType[*iam.ErrSessionNotFound](err); ok {
|
||||
securecookie.Clear(w, cookieConfig)
|
||||
next.ServeHTTP(w, r)
|
||||
session, err := svc.SessionService.GetSession(ctx, sessionID)
|
||||
if err != nil {
|
||||
if _, ok := errors.AsType[*iam.ErrSessionNotFound](err); ok {
|
||||
securecookie.Clear(w, cookieConfig)
|
||||
next.ServeHTTP(w, r)
|
||||
|
||||
return
|
||||
return
|
||||
}
|
||||
|
||||
if _, ok := errors.AsType[*iam.ErrSessionExpired](err); ok {
|
||||
securecookie.Clear(w, cookieConfig)
|
||||
next.ServeHTTP(w, r)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
panic(fmt.Errorf("cannot get session: %w", err))
|
||||
}
|
||||
|
||||
if _, ok := errors.AsType[*iam.ErrSessionExpired](err); ok {
|
||||
securecookie.Clear(w, cookieConfig)
|
||||
next.ServeHTTP(w, r)
|
||||
identity, err := svc.AccountService.GetIdentity(ctx, session.IdentityID)
|
||||
if err != nil {
|
||||
if _, ok := errors.AsType[*iam.ErrIdentityNotFound](err); ok {
|
||||
securecookie.Clear(w, cookieConfig)
|
||||
next.ServeHTTP(w, r)
|
||||
|
||||
return
|
||||
return
|
||||
}
|
||||
|
||||
panic(fmt.Errorf("cannot get identity: %w", err))
|
||||
}
|
||||
|
||||
panic(fmt.Errorf("cannot get session: %w", err))
|
||||
}
|
||||
|
||||
identity, err := svc.AccountService.GetIdentity(ctx, session.IdentityID)
|
||||
if err != nil {
|
||||
if _, ok := errors.AsType[*iam.ErrIdentityNotFound](err); ok {
|
||||
securecookie.Clear(w, cookieConfig)
|
||||
next.ServeHTTP(w, r)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
panic(fmt.Errorf("cannot get identity: %w", err))
|
||||
}
|
||||
|
||||
userAgent := r.UserAgent()
|
||||
// TODO: will work well when no layer 7 proxy is in front of the server
|
||||
var ipAddress net.IP
|
||||
|
||||
Reference in New Issue
Block a user