@@ -6,11 +6,11 @@ import (
6
6
"strconv"
7
7
"strings"
8
8
9
- "github.com/prometheus/client_golang/prometheus"
10
- "github.com/prometheus/client_golang/prometheus/promhttp"
9
+ "github.com/minotar/minecraft"
11
10
12
11
"github.com/gorilla/mux"
13
- "github.com/minotar/minecraft"
12
+ "github.com/prometheus/client_golang/prometheus"
13
+ "github.com/prometheus/client_golang/prometheus/promhttp"
14
14
)
15
15
16
16
type Router struct {
@@ -221,50 +221,38 @@ func fetchSkin(username string) *mcSkin {
221
221
hasTimer .ObserveDuration ()
222
222
stats .MissCache ()
223
223
224
- // Everyone loves nested if statements, right?
225
224
var skin minecraft.Skin
226
225
stats .APIRequested ("GetUUID" )
227
- uuid , err := minecraft .NormalizePlayerForUUID (username )
228
- if err != nil && err .Error () == "unable to GetAPIProfile: user not found" {
229
- log .Debugf ("Failed UUID lookup: %s (%s)" , username , err .Error ())
230
- skin , _ = minecraft .FetchSkinForSteve ()
231
- stats .Errored ("UnknownUser" )
232
- // Don't return yet to ensure we cache the failure
233
- } else {
234
- var catchErr error
235
- // Either no error, or there is one (eg. rate limit or network etc.), but they do possibly still exist
236
- if err != nil && err .Error () == "unable to GetAPIProfile: rate limited" {
237
- log .Noticef ("Failed UUID lookup: %s (%s)" , username , err .Error ())
226
+ uuid , err := mcClient .NormalizePlayerForUUID (username )
227
+ if err != nil {
228
+ switch errorMsg := err .Error (); errorMsg {
229
+
230
+ case "unable to GetAPIProfile: user not found" :
231
+ log .Debugf ("Failed UUID lookup: %s (%s)" , username , errorMsg )
232
+ stats .Errored ("UnknownUser" )
233
+
234
+ case "unable to GetAPIProfile: rate limited" :
235
+ log .Noticef ("Failed UUID lookup: %s (%s)" , username , errorMsg )
238
236
stats .Errored ("LookupUUIDRateLimit" )
239
- catchErr = err
240
- } else if err != nil {
241
- // Other generic issues with looking up UUID, but still worth trying S3
242
- log .Infof ("Failed UUID lookup: %s (%s)" , username , err .Error ())
237
+
238
+ default :
239
+ log .Infof ("Failed UUID lookup: %s (%s)" , username , errorMsg )
243
240
stats .Errored ("LookupUUID" )
244
- catchErr = err
245
- } else {
246
- // We have a UUID, so let's get a skin!
247
- sPTimer := prometheus .NewTimer (getDuration .WithLabelValues ("SessionProfile" ))
248
- skin , catchErr = minecraft .FetchSkinUUID (uuid )
249
- sPTimer .ObserveDuration ()
250
- if catchErr != nil {
251
- log .Noticef ("Failed Skin SessionProfile: %s (%s)" , username , catchErr .Error ())
252
- stats .Errored ("SkinSessionProfile" )
253
- }
241
+
254
242
}
255
- if catchErr != nil {
256
- // Let's fallback to S3 and try and serve at least an old skin...
257
- s3Timer := prometheus . NewTimer ( getDuration . WithLabelValues ( "S3" ) )
258
- skin , err = minecraft . FetchSkinUsernameS3 ( username )
259
- s3Timer . ObserveDuration ()
260
- if err != nil {
261
- log . Debugf ( "Failed Skin S3: %s (%s)" , username , err . Error () )
262
- // Well, looks like they don't exist after all.
263
- skin , _ = minecraft . FetchSkinForSteve ()
264
- stats . Errored ( "FallbackSteve" )
265
- } else {
266
- stats . Errored ( "FallbackUsernameS3" )
267
- }
243
+
244
+ skin , _ = minecraft . FetchSkinForSteve ()
245
+ stats . Errored ( "FallbackSteve" )
246
+ } else {
247
+ // We have a UUID, so let's get a skin!
248
+ sPTimer := prometheus . NewTimer ( getDuration . WithLabelValues ( "SessionProfile" ))
249
+ skin , err = mcClient . FetchSkinUUID ( uuid )
250
+ sPTimer . ObserveDuration ()
251
+ if err != nil {
252
+ log . Noticef ( "Failed Skin SessionProfile: %s (%s)" , username , err . Error () )
253
+ stats . Errored ( "SkinSessionProfile" )
254
+ skin , _ = minecraft . FetchSkinForSteve ( )
255
+ stats . Errored ( "FallbackSteve" )
268
256
}
269
257
}
270
258
0 commit comments