Fix null values in network requests
This commit is contained in:
parent
96277ca3f5
commit
3f5fcadbd5
|
@ -140,12 +140,12 @@ RCT_EXPORT_MODULE()
|
||||||
- (RCTURLRequestCancellationBlock)buildRequest:(NSDictionary *)query
|
- (RCTURLRequestCancellationBlock)buildRequest:(NSDictionary *)query
|
||||||
completionBlock:(void (^)(NSURLRequest *request))block
|
completionBlock:(void (^)(NSURLRequest *request))block
|
||||||
{
|
{
|
||||||
NSURL *URL = [RCTConvert NSURL:query[@"url"]];
|
NSURL *URL = [RCTConvert NSURL:query[@"url"]]; // this is marked as nullable in JS, but should not be null
|
||||||
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:URL];
|
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:URL];
|
||||||
request.HTTPMethod = [[RCTConvert NSString:query[@"method"]] uppercaseString] ?: @"GET";
|
request.HTTPMethod = [[RCTConvert NSString:RCTNilIfNull(query[@"method"])] uppercaseString] ?: @"GET";
|
||||||
request.allHTTPHeaderFields = [RCTConvert NSDictionary:query[@"headers"]];
|
request.allHTTPHeaderFields = [RCTConvert NSDictionary:query[@"headers"]];
|
||||||
|
|
||||||
NSDictionary *data = [RCTConvert NSDictionary:query[@"data"]];
|
NSDictionary *data = [RCTConvert NSDictionary:RCTNilIfNull(query[@"data"])];
|
||||||
return [self processDataForHTTPQuery:data callback:^(NSError *error, NSDictionary *result) {
|
return [self processDataForHTTPQuery:data callback:^(NSError *error, NSDictionary *result) {
|
||||||
if (error) {
|
if (error) {
|
||||||
RCTLogError(@"Error processing request body: %@", error);
|
RCTLogError(@"Error processing request body: %@", error);
|
||||||
|
@ -220,7 +220,7 @@ RCT_EXPORT_MODULE()
|
||||||
* - @"contentType" (NSString): the content type header of the request
|
* - @"contentType" (NSString): the content type header of the request
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
- (RCTURLRequestCancellationBlock)processDataForHTTPQuery:(NSDictionary *)query callback:
|
- (RCTURLRequestCancellationBlock)processDataForHTTPQuery:(nullable NSDictionary *)query callback:
|
||||||
(RCTURLRequestCancellationBlock (^)(NSError *error, NSDictionary *result))callback
|
(RCTURLRequestCancellationBlock (^)(NSError *error, NSDictionary *result))callback
|
||||||
{
|
{
|
||||||
if (!query) {
|
if (!query) {
|
||||||
|
|
|
@ -104,8 +104,7 @@ class XMLHttpRequest extends XMLHttpRequestBase {
|
||||||
sendImpl(method: ?string, url: ?string, headers: Object, data: any): void {
|
sendImpl(method: ?string, url: ?string, headers: Object, data: any): void {
|
||||||
if (typeof data === 'string') {
|
if (typeof data === 'string') {
|
||||||
data = {string: data};
|
data = {string: data};
|
||||||
}
|
} else if (data instanceof FormData) {
|
||||||
if (data instanceof FormData) {
|
|
||||||
data = {formData: data.getParts()};
|
data = {formData: data.getParts()};
|
||||||
}
|
}
|
||||||
RCTNetworking.sendRequest(
|
RCTNetworking.sendRequest(
|
||||||
|
|
Loading…
Reference in New Issue