-
Notifications
You must be signed in to change notification settings - Fork 20
Tweaks to generic API error messaging #1339
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: trunk
Are you sure you want to change the base?
Conversation
There was a problem hiding this 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.' ); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 all5xx
errors - Leave no response as is (in this PR)
- Restore
404
error but otherwise leave4xx
as is (in this PR)
There was a problem hiding this comment.
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 ) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.' ); |
There was a problem hiding this comment.
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 all5xx
errors - Leave no response as is (in this PR)
- Restore
404
error but otherwise leave4xx
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 ); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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?
Ping @dechov 👋 |
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:
...the API client responds with a more appropriate message — though if and how it shows up on the client depends on the context. Examples:
Edit: this now says:
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:
woocommerce-services/classes/class-wc-connect-debug-tools.php
Lines 28 to 35 in 3624a2c
(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:
...we can simplify the message:
Edit: other 5xx errors (such as 502 during server downtime) now yield:
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 [...]":
Error communication per contextManually 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:
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:TODO:WP_Error
in JSON form. Show a notice insteadEdit: now captured in #1364
Also:On failure to fetch payment methods, might want to communicate more about how it failed