Skip to content

Commit 85be976

Browse files
authored
feat!: implement consolidated error codes for getDeliveryVehicle (#73)
* feat!: implement consolidated error codes for getDeliveryVehicle - Add GET_DELIVERY_VEHICLE_ERROR_CODE constant to Android JsErrors.java - Update iOS error constants to match Android naming convention - Replace raw exception rejection with consolidated error code on Android - Ensure error codes and messages are identical across platforms BREAKING CHANGE: getDeliveryVehicle error code updated to GET_DELIVERY_VEHICLE_ERROR_CODE
1 parent 1e7c114 commit 85be976

File tree

5 files changed

+14
-10
lines changed

5 files changed

+14
-10
lines changed

android/src/main/java/com/google/android/react/driversdk/lmfs/DeliveryDriverModule.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,8 +193,10 @@ public void onSuccess(DeliveryVehicle deliveryVehicle) {
193193
}
194194

195195
public void onFailure(@NonNull Throwable thrown) {
196-
// TODO: Expose proper gRPC Error code to RN.
197-
promise.reject(thrown);
196+
promise.reject(
197+
JsErrors.GET_DELIVERY_VEHICLE_ERROR_CODE,
198+
JsErrors.GET_DELIVERY_VEHICLE_ERROR_MESSAGE,
199+
thrown);
198200
}
199201
},
200202
// causes the callbacks to be executed on the main (UI) thread

android/src/main/java/com/google/android/react/driversdk/shared/JsErrors.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,8 @@ public class JsErrors {
4343
public static final String DRIVER_API_NOT_INITIALIZED_CODE = "DRIVER_API_NOT_INITIALIZED_CODE";
4444
public static final String DRIVER_API_NOT_INITIALIZED_MESSAGE =
4545
"Driver API has not been initialized.";
46+
47+
public static final String GET_DELIVERY_VEHICLE_ERROR_CODE = "GET_DELIVERY_VEHICLE_ERROR_CODE";
48+
public static final String GET_DELIVERY_VEHICLE_ERROR_MESSAGE =
49+
"Failed to retrieve delivery vehicle information.";
4650
}

ios/DeliveryDriverController.m

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,7 @@ - (void)getDeliveryVehicle:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseR
8181
[_driverAPI.deliveryVehicleManager
8282
getVehicleWithCompletion:^(GMTDDeliveryVehicle *_Nullable vehicle, NSError *_Nullable error) {
8383
if (error != nil || vehicle == nil) {
84-
reject(kDriverApiFailedToGetDeliveryVehicleCode,
85-
kDriverApiFailedToGetDeliveryVehicleMessage, nil);
84+
reject(kGetDeliveryVehicleErrorCode, kGetDeliveryVehicleErrorMessage, error);
8685
return;
8786
}
8887

ios/JsErrorsConstants.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,5 @@ extern NSString* const kDriverApiAlreadyExistsErrorCode;
2222
extern NSString* const kDriverApiAlreadyExistsErrorMessage;
2323
extern NSString* const kNavigatorNotInitializedErrorCode;
2424
extern NSString* const kNavigatorNotInitializedErrorMessage;
25-
extern NSString* const kDriverApiFailedToGetDeliveryVehicleCode;
26-
extern NSString* const kDriverApiFailedToGetDeliveryVehicleMessage;
25+
extern NSString* const kGetDeliveryVehicleErrorCode;
26+
extern NSString* const kGetDeliveryVehicleErrorMessage;

ios/JsErrorsConstants.m

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
NSString* const kDriverApiAlreadyExistsErrorMessage = @"Driver API already exists.";
2424
NSString* const kNavigatorNotInitializedErrorCode = @"NO_NAVIGATOR_CODE";
2525
NSString* const kNavigatorNotInitializedErrorMessage = @"Navigator is not initialized.";
26-
NSString* const kDriverApiFailedToGetDeliveryVehicleCode =
27-
@"DRIVER_API_FAILED_TO_GET_DELIVERY_VEHICLE";
28-
NSString* const kDriverApiFailedToGetDeliveryVehicleMessage =
29-
@"There was an error retrieving the delivery vehicle";
26+
NSString* const kGetDeliveryVehicleErrorCode = @"GET_DELIVERY_VEHICLE_ERROR_CODE";
27+
NSString* const kGetDeliveryVehicleErrorMessage =
28+
@"Failed to retrieve delivery vehicle information.";

0 commit comments

Comments
 (0)