Skip to content

Commit 03686c2

Browse files
Add error handling to expose server response during failed auth (#111)
Updates the error messaging to include the server response during failed authentication.
1 parent 986ce2a commit 03686c2

File tree

4 files changed

+16
-7
lines changed

4 files changed

+16
-7
lines changed

RELEASE-NOTES.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## 1.1.2
4+
5+
- Updates the error messaging to include the server response during failed authentication [#111](https://github.com/simperium/node-simperium/pull/111)
6+
37
## 1.1.0 - 1.1.1
48

59
- Increase usability in other projects by separating `node` and browser modules [#100](https://github.com/Simperium/node-simperium/pull/100)

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "simperium",
3-
"version": "1.1.1",
3+
"version": "1.1.2",
44
"description": "A simperium client for node.js",
55
"main": "./lib/simperium/index.js",
66
"browser": {

src/simperium/auth.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,16 @@ type User = {
88
access_token: string,
99
};
1010

11-
const fromJSON = ( json: string ): User => {
12-
const data = JSON.parse( json );
13-
if ( ! data.access_token && typeof data.access_token !== 'string' ) {
14-
throw new Error( 'access_token not present' );
15-
}
11+
const fromJSON = (json: string): User => {
12+
let data;
13+
try {
14+
data = JSON.parse(json);
15+
} catch (error) {
16+
throw new Error(json);
17+
}
18+
if (!data.access_token && typeof data.access_token !== 'string') {
19+
throw new Error('access_token not present');
20+
}
1621
return {
1722
options: data,
1823
access_token: new String( data.access_token ).toString()

0 commit comments

Comments
 (0)