From 79be5fa26ccb82381d3086d04e9f4b20df5af113 Mon Sep 17 00:00:00 2001 From: Mostyn Bramley-Moore Date: Thu, 16 Jul 2020 00:45:50 +0200 Subject: [PATCH] asset: log fetches, and recognise failures This change makes it easier to see when the remote asset API's fetch service is being used. It also adds some missing error checking- the standard library http client can fail and return a failure code, without returning an error type. --- server/grpc_asset.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/server/grpc_asset.go b/server/grpc_asset.go index 7e3466ba2..56e5f6533 100644 --- a/server/grpc_asset.go +++ b/server/grpc_asset.go @@ -149,6 +149,11 @@ func (s *grpcServer) fetchItem(uri string, expectedHash string) (bool, string, i defer resp.Body.Close() rc := resp.Body + s.accessLogger.Printf("GRPC ASSET FETCH %s %s", uri, resp.Status) + if resp.StatusCode < 200 || resp.StatusCode >= 300 { + return false, "", int64(-1) + } + expectedSize := resp.ContentLength if expectedHash == "" || expectedSize < 0 { // We can't call Put until we know the hash and size.