Skip to content

Commit

Permalink
avoid panics when calling GetSessionFromContext from inside a remote,
Browse files Browse the repository at this point in the history
this fixes #88
  • Loading branch information
felipejfc committed Feb 14, 2019
1 parent dc28e42 commit 8c9df05
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion app.go
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,12 @@ func Error(err error, code string, metadata ...map[string]string) *errors.Error

// GetSessionFromCtx retrieves a session from a given context
func GetSessionFromCtx(ctx context.Context) *session.Session {
return ctx.Value(constants.SessionCtxKey).(*session.Session)
sessionVal := ctx.Value(constants.SessionCtxKey)
if sessionVal == nil {
logger.Log.Warn("ctx doesn't contain a session, are you calling GetSessionFromCtx from inside a remote?")
return nil
}
return sessionVal.(*session.Session)
}

// GetDefaultLoggerFromCtx returns the default logger from the given context
Expand Down

0 comments on commit 8c9df05

Please sign in to comment.