Skip to content
This repository has been archived by the owner on Sep 19, 2021. It is now read-only.

Commit

Permalink
Merge pull request #36 from truetandem/master
Browse files Browse the repository at this point in the history
Release #1 3/14/17
  • Loading branch information
adelevie committed Mar 14, 2017
2 parents c203c57 + 09da5a5 commit abb2092
Show file tree
Hide file tree
Showing 15 changed files with 770 additions and 99 deletions.
23 changes: 21 additions & 2 deletions api/geo/usps.go
Expand Up @@ -17,6 +17,15 @@ var (

// VerifyAPI is the name of that API that handles address verifications
VerifyAPI = "Verify"

// USPSErrorCodes contains USPS code mapping to eApp error codes
USPSErrorCodes = map[string]string{
"-2147219400": "error.geocode.city",
"-2147219401": "error.geocode.notfound",
"-2147219403": "error.geocode.multiple",
"Default Address": "error.geocode.defaultAddress",
"Partial": "error.geocode.partial",
}
)

// USPSGeocoder geocodes address information using the United States Post Office webservice
Expand Down Expand Up @@ -55,7 +64,16 @@ func (g USPSGeocoder) query(geoValues Values) (results Results, err error) {

// Check if we've encountered an error
if foundAddress.Error != nil {
return results, fmt.Errorf("%v", foundAddress.Error.Description)
if errCode, ok := USPSErrorCodes[foundAddress.Error.Number]; ok {
return results, fmt.Errorf("%v", errCode)
}
return results, fmt.Errorf("%v", "geocode.generic")

}

if strings.ContainsAny(foundAddress.ReturnText, "Default Address") {
errCode := USPSErrorCodes["Default Address"]
return results, fmt.Errorf("%v", errCode)
}

// Generate a normalized Result struct from the address found
Expand All @@ -64,7 +82,8 @@ func (g USPSGeocoder) query(geoValues Values) (results Results, err error) {
// Check if any of values requested to be validate do not match up to what was
// returned by the validation response. If there is a mismatch, mark as partial
if results.HasPartial() {
return results, fmt.Errorf("Geocode contains partial matches. Suggestions are available")
errCode := USPSErrorCodes["Partial"]
return results, fmt.Errorf(errCode)
}

return results, nil
Expand Down
3 changes: 3 additions & 0 deletions api/model/form/state_field.go
Expand Up @@ -87,4 +87,7 @@ var stateList = [...]string{
"PR",
"VI",
"WQ",
"AE",
"AP",
"AA",
}

0 comments on commit abb2092

Please sign in to comment.