From 17e4e4d060aa59278a3a8fc031b21e5621a80827 Mon Sep 17 00:00:00 2001 From: boreq Date: Wed, 1 Nov 2023 07:36:30 +0900 Subject: [PATCH] Fix panic on missing rate limit details I knew this would happen and still didn't fix it. --- service/adapters/twitter/twitter.go | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/service/adapters/twitter/twitter.go b/service/adapters/twitter/twitter.go index e13d088..73d00e7 100644 --- a/service/adapters/twitter/twitter.go +++ b/service/adapters/twitter/twitter.go @@ -137,15 +137,19 @@ func (t *Twitter) GetAccountDetails( func (t *Twitter) logError(err error) { var errorResponse *twitter.ErrorResponse if errors.As(err, &errorResponse) { - t.logger.Error(). + l := t.logger.Error(). WithField("statusCode", errorResponse.StatusCode). WithField("title", errorResponse.Title). WithField("detail", errorResponse.Detail). - WithField("type", errorResponse.Type). - WithField("rateLimit.limit", errorResponse.RateLimit.Limit). - WithField("rateLimit.reset", errorResponse.RateLimit.Reset). - WithField("rateLimit.remaining", errorResponse.RateLimit.Remaining). - Message("received an error response from twitter") + WithField("type", errorResponse.Type) + + if errorResponse.RateLimit != nil { + l = l.WithField("rateLimit.limit", errorResponse.RateLimit.Limit). + WithField("rateLimit.reset", errorResponse.RateLimit.Reset). + WithField("rateLimit.remaining", errorResponse.RateLimit.Remaining) + } + + l.Message("received an error response from twitter") } }