Skip to content

Commit 311c27f

Browse files
committed
handle INVALID_REQUEST on Android
1 parent 8307215 commit 311c27f

File tree

3 files changed

+14
-5
lines changed

3 files changed

+14
-5
lines changed

README.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ SquarePOS.transaction(amountInCents, currency, options)
6464
})
6565
```
6666

67-
### Error Codes
67+
### Errors
6868

6969
There are a number of different error codes, which may differ on Android / iOS. Eventually, an exhaustive list should be compiled here. For now, here are the important ones:
7070

@@ -75,7 +75,12 @@ There are a number of different error codes, which may differ on Android / iOS.
7575
- `NO_NETWORK_CONNECTION`: No network connection on the phone
7676
- `AMOUNT_TOO_SMALL`: `amountInCents` was too small (iOS only)
7777
- `AMOUNT_TOO_LARGE`: `amountInCents` was too large (iOS only)
78+
- `INVALID_REQUEST`: Square Point-of-Sale couldn't process the request (because of malformed data or other) (Android only, check `err.squareResponse` for more information)
7879

7980
Additionally, because this is a young project:
8081

81-
- `UNKNOWN_IOS_ERROR`, `UNKNOWN_ANDROID_ERROR`, if the response from Square SDK wasn't handled by this package. In this case, `originalCode` will be available, passing on what was returned from Square SDK.
82+
- `UNKNOWN_ANDROID_ERROR`, if the response from Square Android SDK if the response wasn't handled by this package. On Android, you'll have access to `err.squareResponse` to see the entire response data sent back from Square Point-of-Sale.
83+
- `UNKNOWN_IOS_ERROR`, if the response from Square iOS SDK wasn't handled by this package.
84+
85+
86+

index.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ const errors = {
1616
UNSUPPORTED_TENDER_TYPE: 'UNSUPPORTED_TENDER_TYPE',
1717
NO_NETWORK_CONNECTION: 'NO_NETWORK_CONNECTION',
1818
TRANSACTION_ALREADY_IN_PROGRESS: 'TRANSACTION_ALREADY_IN_PROGRESS',
19+
INVALID_REQUEST: 'INVALID_REQUEST',
1920
}
2021

2122
const iosErrors = {
@@ -35,6 +36,7 @@ const androidErrors = {
3536
USER_NOT_ACTIVATED: errors.USER_NOT_ACTIVE,
3637
NO_NETWORK: errors.NO_NETWORK_CONNECTION,
3738
TRANSACTION_ALREADY_IN_PROGRESS: errors.TRANSACTION_ALREADY_IN_PROGRESS,
39+
INVALID_REQUEST: errors.INVALID_REQUEST,
3840
}
3941

4042
const RNSquarePos = {
@@ -57,12 +59,14 @@ const RNSquarePos = {
5759
if (data.errorCode) {
5860
if (androidErrors[data.errorCode]) {
5961
return reject({
60-
errorCode: androidErrors[data.errorCode]
62+
errorCode: androidErrors[data.errorCode],
63+
squareResponse: data
6164
})
6265
} else {
6366
return reject({
6467
errorCode: errors.UNKNOWN_ANDROID_ERROR,
65-
originalCode: data.errorCode
68+
originalCode: data.errorCode,
69+
squareResponse: data
6670
})
6771
}
6872
} else {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
{
33
"name": "react-native-square-pos",
4-
"version": "1.0.15",
4+
"version": "1.0.16",
55
"description": "React Native wrapper around Square's Android / iOS POS SDKs",
66
"main": "index.js",
77
"scripts": {

0 commit comments

Comments
 (0)