You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+9Lines changed: 9 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -95,6 +95,15 @@ import AddressSearch from 'react-loqate';
95
95
/>;
96
96
```
97
97
98
+
### Errors
99
+
100
+
Two types of errors can be thrown, LoqateError and ReactLoqateError.
101
+
Loqate Errors are errors from the Loqate API. Their structure, causes and resolutions can be [found in the loqate docs](https://www.loqate.com/developers/api/generic-errors/).
102
+
103
+
Currently only one ReactLoqateError can be thrown. This error occurs when the Retrieve API returns an empty Items array after querying it with an existing ID.
104
+
105
+
It is on you as the implementing party to catch and handle these errors.
106
+
98
107
### Contributing
99
108
100
109
This codebases use [@changesets](https://github.com/changesets/changesets) for release and version management
Copy file name to clipboardExpand all lines: src/utils/__tests__/Loqate.test.ts
+31-5Lines changed: 31 additions & 5 deletions
Original file line number
Diff line number
Diff line change
@@ -41,7 +41,7 @@ describe('Loqate', () => {
41
41
expect({ Items }).toEqual(suggestions);
42
42
});
43
43
44
-
it('should throw loqate errors',async()=>{
44
+
it('should throw errors',async()=>{
45
45
server.use(errorHandler);
46
46
47
47
constloqate=Loqate.create('some-key');
@@ -54,10 +54,36 @@ describe('Loqate', () => {
54
54
limit: 10,
55
55
containerId: 'some-container-id',
56
56
});
57
-
}).rejects.toThrowError(
58
-
newError(
59
-
'Loqate error: {"Error":"2","Description":"Unknown key","Cause":"The key you are using to access the service was not found.","Resolution":"Please check that the key is correct. It should be in the form AA11-AA11-AA11-AA11."}'
60
-
)
57
+
}).rejects.toThrowError(newError('Unknown key'));
58
+
});
59
+
60
+
it('should throw loqate errors',async()=>{
61
+
server.use(errorHandler);
62
+
63
+
constloqate=Loqate.create('some-key');
64
+
65
+
leterror;
66
+
try{
67
+
awaitloqate.find({
68
+
text: 'some-text',
69
+
language: 'some-language',
70
+
countries: ['GB','US'],
71
+
limit: 10,
72
+
containerId: 'some-container-id',
73
+
});
74
+
}catch(e){
75
+
error=e;
76
+
}
77
+
78
+
expect(error).toEqual(newError('Unknown key'));
79
+
expect(JSON.stringify(error)).toEqual(
80
+
JSON.stringify({
81
+
Cause: 'The key you are using to access the service was not found.',
82
+
Description: 'Unknown key',
83
+
Error: '2',
84
+
Resolution:
85
+
'Please check that the key is correct. It should be in the form AA11-AA11-AA11-AA11.',
0 commit comments