This repository was archived by the owner on Feb 4, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 38
Coupons/fetch reports #3012
Merged
Merged
Coupons/fetch reports #3012
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
9eaf31a
Add missing arguments to the fetchCouponsReports
hichamboushaba 878c383
Add Store function to retrieve the most active coupons
hichamboushaba 7618ff9
Add a button to the sample app to test the fetching of most active co…
hichamboushaba d38c728
Extract logic of mapping error to WooError to a single function
hichamboushaba dc910c9
Match `rest_no_route` case when getting 404
hichamboushaba a6935c4
Rename error for better clarity
hichamboushaba 6a77ae8
Add ability to limit list of observed coupons list
hichamboushaba 9d511f8
Allow limiting the list of fetched coupons
hichamboushaba 52cd84a
Add function to retrieve a list of given coupons
hichamboushaba 625df3c
Add argument to disable clearing the DB after the fetch
hichamboushaba File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,59 +32,52 @@ enum class WooErrorType { | |
INVALID_RESPONSE, | ||
AUTHORIZATION_REQUIRED, | ||
INVALID_PARAM, | ||
PLUGIN_NOT_ACTIVE, | ||
API_NOT_FOUND, | ||
EMPTY_RESPONSE, | ||
INVALID_COUPON, | ||
RESOURCE_ALREADY_EXISTS | ||
} | ||
|
||
fun WPComGsonNetworkError.toWooError(): WooError { | ||
val type = when (type) { | ||
TIMEOUT -> WooErrorType.TIMEOUT | ||
NO_CONNECTION, | ||
SERVER_ERROR, | ||
INVALID_SSL_CERTIFICATE, | ||
NETWORK_ERROR -> WooErrorType.API_ERROR | ||
PARSE_ERROR, | ||
CENSORED, | ||
INVALID_RESPONSE -> WooErrorType.INVALID_RESPONSE | ||
HTTP_AUTH_ERROR, | ||
AUTHORIZATION_REQUIRED, | ||
NOT_AUTHENTICATED -> WooErrorType.AUTHORIZATION_REQUIRED | ||
NOT_FOUND -> WooErrorType.INVALID_ID | ||
UNKNOWN, null -> { | ||
when (apiError) { | ||
"rest_invalid_param" -> WooErrorType.INVALID_PARAM | ||
"rest_no_route" -> WooErrorType.PLUGIN_NOT_ACTIVE | ||
else -> WooErrorType.GENERIC_ERROR | ||
} | ||
fun WPComGsonNetworkError.toWooError() = WooError( | ||
type = type.getWooErrorType(apiError), | ||
original = type, | ||
message = message | ||
) | ||
|
||
fun WPAPINetworkError.toWooError() = WooError( | ||
type = type.getWooErrorType(errorCode), | ||
original = type, | ||
message = message | ||
) | ||
|
||
private fun GenericErrorType?.getWooErrorType(apiError: String?) = when (this) { | ||
TIMEOUT -> WooErrorType.TIMEOUT | ||
NO_CONNECTION, | ||
SERVER_ERROR, | ||
INVALID_SSL_CERTIFICATE, | ||
NETWORK_ERROR -> WooErrorType.API_ERROR | ||
|
||
PARSE_ERROR, | ||
CENSORED, | ||
INVALID_RESPONSE -> WooErrorType.INVALID_RESPONSE | ||
|
||
HTTP_AUTH_ERROR, | ||
AUTHORIZATION_REQUIRED, | ||
NOT_AUTHENTICATED -> WooErrorType.AUTHORIZATION_REQUIRED | ||
|
||
NOT_FOUND -> { | ||
when (apiError) { | ||
"rest_no_route" -> WooErrorType.API_NOT_FOUND | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We need this specific differentiation now, the new error type will help identify when the |
||
else -> WooErrorType.INVALID_ID | ||
} | ||
} | ||
return WooError(type, this.type, message) | ||
} | ||
|
||
fun WPAPINetworkError.toWooError(): WooError { | ||
val type = when (type) { | ||
TIMEOUT -> WooErrorType.TIMEOUT | ||
NO_CONNECTION, | ||
SERVER_ERROR, | ||
INVALID_SSL_CERTIFICATE, | ||
NETWORK_ERROR -> WooErrorType.API_ERROR | ||
PARSE_ERROR, | ||
CENSORED, | ||
INVALID_RESPONSE -> WooErrorType.INVALID_RESPONSE | ||
HTTP_AUTH_ERROR, | ||
AUTHORIZATION_REQUIRED, | ||
NOT_AUTHENTICATED -> WooErrorType.AUTHORIZATION_REQUIRED | ||
NOT_FOUND -> WooErrorType.INVALID_ID | ||
UNKNOWN, null -> { | ||
when (errorCode) { | ||
"rest_invalid_param" -> WooErrorType.INVALID_PARAM | ||
"rest_no_route" -> WooErrorType.PLUGIN_NOT_ACTIVE | ||
"woocommerce_rest_invalid_coupon" -> WooErrorType.INVALID_COUPON | ||
else -> WooErrorType.GENERIC_ERROR | ||
} | ||
UNKNOWN, null -> { | ||
when (apiError) { | ||
"rest_invalid_param" -> WooErrorType.INVALID_PARAM | ||
"rest_no_route" -> WooErrorType.API_NOT_FOUND | ||
"woocommerce_rest_invalid_coupon" -> WooErrorType.INVALID_COUPON | ||
else -> WooErrorType.GENERIC_ERROR | ||
} | ||
} | ||
return WooError(type, this.type, message) | ||
} |
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 was the one who introduced
PLUGIN_NOT_ACTIVE
during the REST API project, it was to match the value emitted by the Order REST client, but I think that name was not the right choice, the error could happen for any non-existing endpoint, be it because the plugin is not active, or any other reason, so I renamed it to make it more clear, please let me know what you think?And this is a breaking change for WCAndroid, so let's not merge this until the WCAndroid PR is ready.