Skip to content

Commit 5443ae3

Browse files
committed
throw default message only when there is no data
1 parent b1d5399 commit 5443ae3

1 file changed

Lines changed: 22 additions & 1 deletion

File tree

src/api/auth.js

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,27 @@ export default class Auth {
4646
});
4747
}
4848

49+
_processJWTinSignup(promise, jwt) {
50+
return promise.then(response => {
51+
jwt = response.headers.get('jwt');
52+
return response.json();
53+
})
54+
.then(data => {
55+
if (data.email) {
56+
return {
57+
user,
58+
jwt,
59+
};
60+
}
61+
62+
if (data.errors) {
63+
throw data.errors;
64+
}
65+
66+
throw new Error('Server error, try again later. Sorry for inconvenience :(');
67+
});
68+
}
69+
4970
// @method signup(email: String, name: String, password: String): Promise
5071
// Register new user
5172
signup(email, name, password) {
@@ -60,7 +81,7 @@ export default class Auth {
6081
}
6182
);
6283

63-
return this._processJWT(signupPromise, jwt);
84+
return this._processJWTinSignup(signupPromise, jwt);
6485
}
6586

6687
// @method login(email: String, password: String, org: String): Promise<LoginResponse>

0 commit comments

Comments
 (0)