Created
September 21, 2021 08:37
-
-
Save mindshifter/6d96f59df7fcc996bd222e1560517fbb to your computer and use it in GitHub Desktop.
Errors
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if (errorBody != null) { | |
try { | |
val serverError = gson.fromJson(errorBody.string(), ServerError::class.java) | |
serverError.url = raw().request.url.toString() | |
Firebase.crashlytics.recordException(serverError.toException()) | |
throw when (code()) { | |
401, 403 -> UnauthorizedException() | |
400, 404, 422 -> { | |
when (serverError.error) { | |
CART_NOT_EXIST -> CartNotFoundException() | |
SPECIALIST_NOT_AVAILABLE_ERROR -> SpecialistNotAvailableException() | |
INVALID_PHONE_FORMAT -> InvalidPhoneFormatException() | |
CART_INVALID_SHIPPING_TOKEN -> ShippingAddressException() | |
ITEM_OUT_OF_STOCK -> ItemOutOfStockException() | |
ORDER_NOT_FOUND -> OrderNotFoundException() | |
ORDER_CANT_BE_EDITED -> OrderCantBeEditedException() | |
CUSTOMER_NOT_FOUND -> CustomerNotFoundException() | |
INVALID_ORDER_STATUS_TYPE -> InvalidOrderStatusTypeException() | |
CUSTOMER_EMAIL_ALREADY_EXISTS -> CustomerEmailAlreadyExistsException() | |
else -> ServerException(serverError) | |
} | |
} | |
else -> ServerException(serverError) | |
} | |
} catch (throwable: Throwable) { | |
throw throwable | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment