Skip to content

Commit

Permalink
fix: throw an error when bundle download was unsuccessful on iOS (#745)
Browse files Browse the repository at this point in the history
* fix: On iOS ,if download bundle was not successful,throw an error.

* chore: add changeset

---------

Co-authored-by: Rain_Jiang <[email protected]>
  • Loading branch information
ra1nj and rainjiang authored Sep 12, 2024
1 parent 300524b commit dbbaf72
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/loud-falcons-prove.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@callstack/repack': patch
---

Fix download bundle error not threw on iOS issue
10 changes: 10 additions & 0 deletions packages/repack/ios/ScriptManager.mm
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,18 @@ - (void)downloadAndCache:(ScriptConfig *)config completionHandler:(void (^)(NSEr
NSURLSessionDataTask *task = [[NSURLSession sharedSession]
dataTaskWithRequest:request
completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *)response;
NSInteger statusCode = [httpResponse statusCode];
if (error != nil) {
callback(error);
} else if (statusCode < 200 || statusCode >= 300) {
NSDictionary *userInfo = @{
NSLocalizedFailureReasonErrorKey : [NSString
stringWithFormat:@"Request should have returned with 200 HTTP status, but instead it received %ld",
(long)statusCode]
};
NSError *httpError = [NSError errorWithDomain:NSURLErrorDomain code:statusCode userInfo:userInfo];
callback(httpError);
} else {
@try {
NSDictionary<NSString *, id> *result = [CodeSigningUtils extractBundleAndTokenWithFileContent:data];
Expand Down

0 comments on commit dbbaf72

Please sign in to comment.