@@ -159,6 +159,7 @@ - (NSString *)URLWithName:(NSString *)name {
159159
160160- (void )callFunction : (NSString *)name
161161 withObject : (nullable id )data
162+ timeout : (NSTimeInterval )timeout
162163 completion : (void (^)(FIRHTTPSCallableResult *_Nullable result,
163164 NSError *_Nullable error))completion {
164165 [_contextProvider getContext: ^(FUNContext *_Nullable context, NSError *_Nullable error) {
@@ -168,16 +169,25 @@ - (void)callFunction:(NSString *)name
168169 }
169170 return ;
170171 }
171- return [self callFunction: name withObject: data context: context completion: completion];
172+ return [self callFunction: name
173+ withObject: data
174+ timeout: timeout
175+ context: context
176+ completion: completion];
172177 }];
173178}
174179
175180- (void )callFunction : (NSString *)name
176181 withObject : (nullable id )data
182+ timeout : (NSTimeInterval )timeout
177183 context : (FUNContext *)context
178184 completion : (void (^)(FIRHTTPSCallableResult *_Nullable result,
179185 NSError *_Nullable error))completion {
180- GTMSessionFetcher *fetcher = [_fetcherService fetcherWithURLString: [self URLWithName: name]];
186+ NSURL *url = [NSURL URLWithString: [self URLWithName: name]];
187+ NSURLRequest *request = [NSURLRequest requestWithURL: url
188+ cachePolicy: NSURLRequestUseProtocolCachePolicy
189+ timeoutInterval: timeout];
190+ GTMSessionFetcher *fetcher = [_fetcherService fetcherWithRequest: request];
181191
182192 NSMutableDictionary *body = [NSMutableDictionary dictionary ];
183193 // Encode the data in the body.
@@ -225,6 +235,11 @@ - (void)callFunction:(NSString *)name
225235 if ([error.domain isEqualToString: kGTMSessionFetcherStatusDomain ]) {
226236 error = FUNErrorForResponse (error.code , data, serializer);
227237 }
238+ if ([error.domain isEqualToString: NSURLErrorDomain ]) {
239+ if (error.code == NSURLErrorTimedOut) {
240+ error = FUNErrorForCode (FIRFunctionsErrorCodeDeadlineExceeded);
241+ }
242+ }
228243 } else {
229244 // If there wasn't an HTTP error, see if there was an error in the body.
230245 error = FUNErrorForResponse (200 , data, serializer);
0 commit comments