Skip to content

Conversation

dechov
Copy link
Contributor

@dechov dechov commented Mar 15, 2018

Aims to make sure error messaging is adequate in all cases where the server couldn't be reached or returns a 500 status.

Generic message

If the server couldn't be reached

Instead of:

screen shot 2018-02-06 at 6 09 09 pm

...the API client responds with a more appropriate message — though if and how it shows up on the client depends on the context. Examples:

screen shot 2018-03-15 at 11 23 17 am

screen shot 2018-03-14 at 6 29 51 pm

Edit: this now says:

The WooCommerce Services API encountered an error. Please try again.

The reference to the server is changed from "WooCommerce Services server" (kind of inelegant as a result of the renaming to "WooCommerce Services") to "WooCommerce Services API", based on a precedent in the connection test tool:

function test_connection() {
$test_request = $this->api_client->auth_test();
if ( $test_request && ! is_wp_error( $test_request ) && $test_request->authorized ) {
echo '<div class="updated inline"><p>' . __( 'Your site is succesfully communicating to the WooCommerce Services API.', 'woocommerce-services' ) . '</p></div>';
} else {
echo '<div class="error inline"><p>' . __( 'ERROR: Your site has a problem connecting to the WooCommerce Services API. Please make sure your Jetpack connection is working.', 'woocommerce-services' ) . '</p></div>';
}
}

(Some discussion in p1521044361000197-slack-hydra of the suggestion to check whether requests can go out at all. If possible, we should consider only showing this if we have particular reason to believe this might be the case — perhaps only if no server requests have yet succeeded.)

Internal server error

If a 500 error comes back, there is generally no information specific to the error we can communicate via the client, so instead of:

screen shot 2018-03-15 at 2 43 57 pm

...we can simplify the message:

screen shot 2018-03-15 at 1 43 50 pm

Edit: other 5xx errors (such as 502 during server downtime) now yield:

The WooCommerce Services API is unavailable. Please try again in just a moment.

4xx errors

If available, the raw error message is passed through, without the HTTP status or meta-error message "Error: The WooCommerce Services server returned [...]":

screen shot 2018-02-13 at 2 38 49 pm

Error communication per context

Manually tested all relevant cases by searching for $this->api_client-> in the codebase. Some e2e tests might be helpful so as to be confident errors are and will continue to be properly communicated.

To test global notices:

  • For internal server error message, can point payment proxy on local server to a URL where there is no server responding, and then trigger any of these:

    • Label status fetch on order page load
    • Label refund request
  • For unreachable server message, can set WOOCOMMERCE_CONNECT_SERVER_URL to a URL where there is no WCS server responding, and then trigger any of the above, or:

    • Shipping rate fetch (on cart/checkout page, with debug mode enabled)
    • Label rate fetch
    • Label purchase request

TODO:

Edit: now captured in #1364

Also:

  • On failure to fetch payment methods, might want to communicate more about how it failed

Copy link
Contributor

@jeffstieler jeffstieler left a comment

Choose a reason for hiding this comment

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

Questions about message verbiage.

} elseif ( 500 < $response_code ) {
return new WP_Error( 'wcc_server_error', 'The WooCommerce Services API is unavailable. Please try again in just a moment.' );
} elseif ( 400 <= $response_code ) {
return new WP_Error( 'wcc_server_error', 'The WooCommerce Services API could not process the request.' );
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you explain your reasoning for these error messages? (and the ones below)

At a glance it looks like all of these could be one of two messages - either "could not be reached" or "encountered an error".

Why do some not prompt the user to try again?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is definitely wide open to revision but here's the understanding on which I based it:

  • No error code means the server wasn't reached at all, for reasons unrelated to WCS. Even though it may be something like a network hiccup, there's no WCS-specific reason to think trying again might help.
  • 500 means something went wrong on the server, perhaps a bug in the server application, and there's no way to know whether trying again will help but there's nothing else we can suggest without manual investigation.
  • 502 means the WCS server is down. If due to a deploy, it'll be back up within a few seconds, and otherwise, it'll be back up some time soon — trying again is the only thing you can do and it should eventually work.
  • 4xx means there's something about the request the server can't or won't process — no need to try again with the same request.

I'm actually a little bit uneasy about showing "Please try again." for a 500 error over and over each time they try, since it could well be that it will never work. I think — ideally — this response would indicate a very exceptional case, in which contacting support would be justified.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok so how about we:

  • Remove "please try again" from all error messages.
  • Show The WooCommerce Services API encountered an error. for all 5xx errors
  • Leave no response as is (in this PR)
  • Restore 404 error but otherwise leave 4xx as is (in this PR)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jeffstieler This had fallen off my radar – sorry about that.

I'm good with those changes except that I think "The WooCommerce Services API encountered an error." could be a little bit misleading, at least for the 502 case: as far as I understand, it's the HTTP server that "encountered an error", the error being that the WCS application hasn't properly started (yet?).

It seems worth communicating that it has nothing to do with content of the request itself. For 502 responses, proposing "The WooCommerce Services API is momentarily unavailable." – what do you think? If 👎, I'll go ahead with the change as you'd described.

return new WP_Error( 'wcc_server_error', 'The WooCommerce Services API encountered an error. Please try again.' );
} elseif ( 500 < $response_code ) {
return new WP_Error( 'wcc_server_error', 'The WooCommerce Services API is unavailable. Please try again in just a moment.' );
} elseif ( 400 <= $response_code ) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't know how common/possible it would be in non-development environments, but I see 404s a lot on the order details page when switching between my local WCS server and staging/production.

This change removes the meaningful "not found" I saw before.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍 Will bring back that string for 4xx responses at least.

} elseif ( 500 < $response_code ) {
return new WP_Error( 'wcc_server_error', 'The WooCommerce Services API is unavailable. Please try again in just a moment.' );
} elseif ( 400 <= $response_code ) {
return new WP_Error( 'wcc_server_error', 'The WooCommerce Services API could not process the request.' );
Copy link
Contributor

Choose a reason for hiding this comment

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

Ok so how about we:

  • Remove "please try again" from all error messages.
  • Show The WooCommerce Services API encountered an error. for all 5xx errors
  • Leave no response as is (in this PR)
  • Restore 404 error but otherwise leave 4xx as is (in this PR)

return new WP_Error( 'wcc_server_error_response', 'The WooCommerce Services API is unavailable. Please try again in just a moment.' );
}

return new WP_Error( 'wcc_server_error_response', $message, $data );
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we keep this DRY?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just to be sure, are you referring to the repetition of the code, the message, or both?

@jeffstieler
Copy link
Contributor

Ping @dechov 👋

@brezocordero brezocordero changed the base branch from master to trunk April 21, 2021 17:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants