@@ -165,7 +165,12 @@ func (t *Transport) executeGsRequest(ctx context.Context, internalCtx context.Co
165165 }
166166
167167 log .Debugf ("finished executing graphsync request for channel %s" , channelID )
168- err := t .events .OnChannelCompleted (channelID , lastError == nil )
168+
169+ var completeErr error
170+ if lastError != nil {
171+ completeErr = xerrors .Errorf ("graphsync request failed to complete: %w" , lastError )
172+ }
173+ err := t .events .OnChannelCompleted (channelID , completeErr )
169174 if err != nil {
170175 log .Error (err )
171176 }
@@ -533,13 +538,45 @@ func (t *Transport) gsCompletedResponseListener(p peer.ID, request graphsync.Req
533538 return
534539 }
535540
536- if status != graphsync .RequestCancelled {
537- success := status == graphsync .RequestCompletedFull
538- err := t .events .OnChannelCompleted (chid , success )
539- if err != nil {
540- log .Error (err )
541- }
541+ if status == graphsync .RequestCancelled {
542+ return
543+ }
544+
545+ var completeErr error
546+ if status != graphsync .RequestCompletedFull {
547+ statusStr := gsResponseStatusCodeString (status )
548+ completeErr = xerrors .Errorf ("graphsync response to peer %s did not complete: response status code %s" , p , statusStr )
549+ }
550+ err := t .events .OnChannelCompleted (chid , completeErr )
551+ if err != nil {
552+ log .Error (err )
553+ }
554+ }
555+
556+ // Remove this map once this PR lands: https://github.com/ipfs/go-graphsync/pull/148
557+ var gsResponseStatusCodes = map [graphsync.ResponseStatusCode ]string {
558+ graphsync .RequestAcknowledged : "RequestAcknowledged" ,
559+ graphsync .AdditionalPeers : "AdditionalPeers" ,
560+ graphsync .NotEnoughGas : "NotEnoughGas" ,
561+ graphsync .OtherProtocol : "OtherProtocol" ,
562+ graphsync .PartialResponse : "PartialResponse" ,
563+ graphsync .RequestPaused : "RequestPaused" ,
564+ graphsync .RequestCompletedFull : "RequestCompletedFull" ,
565+ graphsync .RequestCompletedPartial : "RequestCompletedPartial" ,
566+ graphsync .RequestRejected : "RequestRejected" ,
567+ graphsync .RequestFailedBusy : "RequestFailedBusy" ,
568+ graphsync .RequestFailedUnknown : "RequestFailedUnknown" ,
569+ graphsync .RequestFailedLegal : "RequestFailedLegal" ,
570+ graphsync .RequestFailedContentNotFound : "RequestFailedContentNotFound" ,
571+ graphsync .RequestCancelled : "RequestCancelled" ,
572+ }
573+
574+ func gsResponseStatusCodeString (code graphsync.ResponseStatusCode ) string {
575+ str , ok := gsResponseStatusCodes [code ]
576+ if ok {
577+ return str
542578 }
579+ return gsResponseStatusCodes [graphsync .RequestFailedUnknown ]
543580}
544581
545582func (t * Transport ) cleanupChannel (chid datatransfer.ChannelID , gsKey graphsyncKey ) {
0 commit comments