Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions Libraries/Image/RCTImageLoader.mm
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,15 @@ static uint64_t monotonicTimeGetCurrentNanoseconds(void)
return (mach_absolute_time() * tb_info.numer) / tb_info.denom;
}

static NSError* addResponseHeadersToError(NSError* originalError, NSHTTPURLResponse* response) {
NSMutableDictionary<NSString*, id>* _userInfo = (NSMutableDictionary<NSString*, id>*)originalError.userInfo.mutableCopy;
_userInfo[@"httpStatusCode"] = [NSNumber numberWithInt:response.statusCode];
_userInfo[@"httpResponseHeaders"] = response.allHeaderFields;
NSError *error = [NSError errorWithDomain:originalError.domain code:originalError.code userInfo:_userInfo];

return error;
}

@interface RCTImageLoader() <NativeImageLoaderIOSSpec, RCTImageLoaderWithAttributionProtocol>

@end
Expand Down Expand Up @@ -523,6 +532,10 @@ - (RCTImageURLLoaderRequest *)_loadImageOrDataWithURLRequest:(NSURLRequest *)req
}
});
} else if (!std::atomic_load(cancelled.get())) {
if (response && error && [response isKindOfClass: [NSHTTPURLResponse class]]) {
NSHTTPURLResponse* _httpResp = (NSHTTPURLResponse*)response;
error = addResponseHeadersToError(error, _httpResp);
}
completionBlock(error, imageOrData, imageMetadata, cacheResult, response);
}
};
Expand Down
2 changes: 1 addition & 1 deletion Libraries/Image/RCTImageView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ - (void)imageLoaderLoadedImage:(UIImage *)loadedImage error:(NSError *)error for
});

if (_onError) {
_onError(@{ @"error": error.localizedDescription });
_onError(@{ @"error": error.localizedDescription, @"responseCode": (error.userInfo[@"httpStatusCode"]?: [NSNull null]), @"httpResponseHeaders": (error.userInfo[@"httpResponseHeaders"] ?: [NSNull null]) });
}
if (_onLoadEnd) {
_onLoadEnd(nil);
Expand Down