fine-grained errors reporting for PaymentAddress#712
Conversation
|
First draft ready for review. This part only deals with errors related to shipping addresses. Will start working on #705, which will then give us the ability to correct both address-releated errors and Payer Errors (e.g., bad email) in the |
| Secondly, the string value allows the developer to describe the | ||
| validation error (and possibly how the end user can fix the error). | ||
| </p> | ||
| <p class="note"> |
There was a problem hiding this comment.
Kept this (languageCodeError) for completeness... but wonder if we should just ditch languageCodeError. 🤔
There was a problem hiding this comment.
Clarified what "this" was above.
| </h2> | ||
| <pre class="idl"> | ||
| dictionary AddressErrorFields { | ||
| DOMString addressLineError; |
There was a problem hiding this comment.
Decided to postfix all these with "Error" in the name, as I felt it made it a little bit more clear when in userland code.
There was a problem hiding this comment.
The extra "Error" suffix feels redundant me, as it should be implied since these are members of the shippingAddressErrors property.
There was a problem hiding this comment.
depends... the problem I ran into was in destructuring and using object short hands. Also, consider the shippingAddressErrors can be the result of another function. Thus:
function validateAddress(address){
// whoops, now "postalCode" has been squatted.
const { postalCode } = address;
const postalCodeError = !isValidPostCode(postCode) ? "Invalid zip code" : undefined;
return { postalCodeError }
}
function collectErrors(response) {
// same problem here!
const { shippingAddress } = response;
const shippingAddressErrors = validateAddress(shippingAddress);
return { shippingAddressErrors }
}And so on...
There was a problem hiding this comment.
I tend to agree this is redundant. I think you have chosen a code style with a combination of object literal shorthand, destructuring, and redundant variable declarations that makes it extra confusing. But I don't think that's a good reason to verbose-ify the API, personally. I would instead suggest writing your code in a more conventional way, such as
function validateAddress(address){
return {
postalCode: !isValidPostalCode(address.postalCode) ? "Invalid zip code" : undefined
};
}
function collectErrors(response) {
return {
shippingAddress: validateAddress(response.shippingAddress)
};
}(basically, don't declare variables you're only going to use once.
|
We have a partial implementation of this in Firefox now (currently based on the original proposal - but will get updated to match the new one soon). |
ef9c30d to
3350316
Compare
|
@domenic, when you have a few mins, would appreciate a final review. We've landed this in Firefox. |
domenic
left a comment
There was a problem hiding this comment.
Mostly LGTM, although I agree with others who are concerned about the redundancy. Will leave it to you to make the call though.
| </h2> | ||
| <pre class="idl"> | ||
| dictionary AddressErrorFields { | ||
| DOMString addressLineError; |
There was a problem hiding this comment.
I tend to agree this is redundant. I think you have chosen a code style with a combination of object literal shorthand, destructuring, and redundant variable declarations that makes it extra confusing. But I don't think that's a good reason to verbose-ify the API, personally. I would instead suggest writing your code in a more conventional way, such as
function validateAddress(address){
return {
postalCode: !isValidPostalCode(address.postalCode) ? "Invalid zip code" : undefined
};
}
function collectErrors(response) {
return {
shippingAddress: validateAddress(response.shippingAddress)
};
}(basically, don't declare variables you're only going to use once.
index.html
Outdated
| <p> | ||
| The members of the <a>AddressErrorFields</a> dictionary represent | ||
| validation errors with specific parts of a <a>physical address</a>. | ||
| Each dictionary member has a dual function: firstly, it denotes that |
There was a problem hiding this comment.
I'd say "firstly, its presence denotes..."
| // Empty shippingOptions implies that we can't ship | ||
| // to this address. | ||
| const shippingOptions = []; | ||
| return { error, shippingAddressErrors, shippingOptions }; |
There was a problem hiding this comment.
Empty shippingOptions should not be necessary, since not-present gets converted to empty in the processing model, I am pretty sure.
There was a problem hiding this comment.
In the "update a PaymentRequest's details algorithm", we do an incremental update to request, so:
If the
shippingOptionsmember of details is present, andrequest.[[options]].requestShippingis true, then:
- Set request.[[details]].shippingOptions to shippingOptions.
Otherwise, the original shipping options are retained - so the developer needs to be explicitly thrash them.
|
@ianbjacobs, could you please republish the document on TR? |
|
Hi @marcoscaceres, I have send a publication request for 7 June. Thanks for all the editing! |
|
Added tests web-platform-tests/wpt#12396 |
closes #647
The following tasks have been completed:
Implementation commitment:
Impact on Payment Handler spec?
Preview | Diff