Skip to content

Commit

Permalink
Improved error message during refresh token process (#5)
Browse files Browse the repository at this point in the history
* improved error message during refresh token process

* unified error responses in all public methods
  • Loading branch information
TheFe91 authored Sep 23, 2020
1 parent edd0edd commit e976f95
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-native-keycloak-plugin",
"version": "0.5.0",
"version": "0.5.1",
"description": "Functional React Native module for authentication between a client and the keycloak server.",
"main": "src/index.js",
"scripts": {
Expand Down
20 changes: 11 additions & 9 deletions src/Core.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ export const apiLogin = async (conf, username, password, scope = 'info') => {
return jsonResponse;
}

console.error(`Error during kc-api-login, ${fullResponse.status}: ${jsonResponse.error_description}`);
return Promise.reject(fullResponse);
console.error(`Error during kc-api-login, ${fullResponse.status}: ${jsonResponse.url}`);
return Promise.reject(jsonResponse.error_description);
};

export const retrieveUserInfo = async () => {
Expand All @@ -122,13 +122,14 @@ export const retrieveUserInfo = async () => {
const headers = { ...basicHeaders, Authorization: `Bearer ${savedTokens.access_token}` };
const options = { headers, method };
const fullResponse = await fetch(userInfoUrl, options);
const jsonResponse = await fullResponse.json();

if (fullResponse.ok) {
return fullResponse.json();
return jsonResponse;
}

console.error(`Error during kc-retrieve-user-info: ${fullResponse.status}`);
return Promise.reject(fullResponse);
console.error(`Error during kc-retrieve-user-info: ${fullResponse.status}: ${fullResponse.url}`);
return Promise.reject(jsonResponse.error_description);
};

export const refreshToken = async () => {
Expand Down Expand Up @@ -159,15 +160,15 @@ export const refreshToken = async () => {
const options = { headers: basicHeaders, method, body };

const fullResponse = await fetch(refreshTokenUrl, options);
const jsonResponse = await fullResponse.json();

if (fullResponse.ok) {
const jsonResponse = await fullResponse.json();
await TokenStorage.saveTokens(jsonResponse);
return jsonResponse;
}

console.error(`Error during kc-refresh-token, ${fullResponse.status}: ${fullResponse.url}`);
return Promise.reject(fullResponse);
return Promise.reject(jsonResponse.error_description);
};

export const logout = async () => {
Expand All @@ -194,6 +195,7 @@ export const logout = async () => {
return Promise.resolve();
}

console.error(`Error during kc-logout: ${fullResponse.status}`);
return Promise.reject(fullResponse);
const jsonResponse = await fullResponse.json();
console.error(`Error during kc-logout: ${fullResponse.status}: ${fullResponse.url}`);
return Promise.reject(jsonResponse.error_description);
};

0 comments on commit e976f95

Please sign in to comment.