Skip to content

Azure Communication Services - Refactor PhoneNumberAsyncClient to Wrap Exceptions#15794

Merged
waynemo merged 3 commits intoAzure:feature/communication/phonenumberfrom
waynemo:phonenumberadmin_exceptions
Sep 29, 2020
Merged

Azure Communication Services - Refactor PhoneNumberAsyncClient to Wrap Exceptions#15794
waynemo merged 3 commits intoAzure:feature/communication/phonenumberfrom
waynemo:phonenumberadmin_exceptions

Conversation

@waynemo
Copy link
Contributor

@waynemo waynemo commented Sep 29, 2020

Refactor methods in PhoneNumberAsyncClient to ensure methods return Mono.error or Flux.error instead of throwing exceptions.

The changes address the comment here:
#15497 (comment)

@waynemo waynemo marked this pull request as ready for review September 29, 2020 06:24
@@ -80,10 +94,8 @@ PagedFlux<AcquiredPhoneNumber> listAllPhoneNumbers(String locale, Context contex
@ServiceMethod(returns = ReturnType.SINGLE)
public Mono<AreaCodes> getAllAreaCodes(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not related to the immediate change, but wondering why these methods are not following the 'list' paradigm, like listAreaCodes, listAreaCodesWithResponse etc.?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The main difference here the return value. AreaCodes is a composite object that contains data. It is not a pageable list in this case, so we are not using the list* convention.

To avoid confusion, perhaps we can rename it to "getAreaCodes()" instead in a separate PR.

locationOptionsQueries.setLocationOptions(locationOptions);
return phoneNumberAdministrations.getAllAreaCodesAsync(
locationType, countryCode, phonePlanId, locationOptionsQueries);
return getAllAreaCodesWithResponse(locationType, countryCode, phonePlanId, locationOptions)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't it better to invoke the regular (without response) method and wrap in an exception.. this process of invoking getAllAreaCodesWithResponse and then trying to flatten doesn't look very clean?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can get the Entity model from the *WithResponse method, but we cannot get the Response information from the regular method (without response). So if we want to reuse the methods we need to start from the *WithResponse method.

@@ -61,11 +67,19 @@ public final class PhoneNumberAsyncClient {
*/
@ServiceMethod(returns = ReturnType.COLLECTION)
public PagedFlux<AcquiredPhoneNumber> listAllPhoneNumbers(String locale) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small clarification, based on the guidelines shouldn't it be listPhoneNumbers? Maybe 'list' and 'listAll' are both OK, just trying to get some understanding here, this is what I see in the doc..

YOU SHOULD remain flexible and use names best suited for developer experience. Don’t let the naming rules result in non-idiomatic naming patterns. For example, Java developers prefer list operations over getAll operations.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the guidelines are more concerned with the 'list' vs 'get' prefix. So both 'list' and 'listAll' will work to differentiate from 'get'.

The potential improvement might be to remove 'All' since it is a bit redundant. Let's revisit that separately.

@waynemo waynemo merged commit 506c61d into Azure:feature/communication/phonenumber Sep 29, 2020
waynemo added a commit to waynemo/azure-sdk-for-java that referenced this pull request Sep 29, 2020
…p Exceptions (Azure#15794)

* Catch exceptions and return error Mono/PagedFlux

* Refactor PhoneNumberAsyncClient method overloads to consolidate logic
ankitarorabit pushed a commit to ankitarorabit/azure-sdk-for-java that referenced this pull request Oct 1, 2020
…p Exceptions (Azure#15794)

* Catch exceptions and return error Mono/PagedFlux

* Refactor PhoneNumberAsyncClient method overloads to consolidate logic
RezaJooyandeh pushed a commit that referenced this pull request Oct 2, 2020
* Azure Communication Service - Phone Number Administration SDK (#15497)

* Add Phone Number functionality to azure-communication-administration

* Update checkstyle suppressions

* Azure Communication Services - Refactor PhoneNumberAsyncClient to Wrap Exceptions (#15794)

* Catch exceptions and return error Mono/PagedFlux

* Refactor PhoneNumberAsyncClient method overloads to consolidate logic

* Azure Communication Service - Update Phone Number Admin Null Checks (#15811)

* Add null checks for required method arguments

* Remove setter null check to allow clearing of httpPipeline

* Updating azure-communication-administration README with a few samples (#15816)

* Updating javadoc with a few samples

* resolve comments

* Fixing spot check errors

* fix typo

* Add Env Var check to skip PhoneNumber integration tests (#15855)

* Samples and Readme update for Administration package (#15853)

* More samples and readme changes

* PR comments

* build failure

* fix indentation

* azure-communication-administration - Regenerate Code for Updated Swagger (#15861)

* Update swagger and regenerate code

* Fix tests after code regeneration

* Fix the param name

* updating the sample code

Co-authored-by: waynemo <wamo@microsoft.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants