Skip to content

Instantly share code, notes, and snippets.

@mindshifter
Created September 21, 2021 08:37
Show Gist options
  • Save mindshifter/6d96f59df7fcc996bd222e1560517fbb to your computer and use it in GitHub Desktop.
Save mindshifter/6d96f59df7fcc996bd222e1560517fbb to your computer and use it in GitHub Desktop.
Errors
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