refactor: adapt errors in apps

This commit is contained in:
Ali BARIN
2022-11-06 18:55:38 +01:00
committed by Faruk AYDIN
parent 5df7867b6d
commit ad46b3eea3
6 changed files with 80 additions and 104 deletions

View File

@@ -1,4 +1,4 @@
import { IJSONObject, IField, IGlobalVariable } from '@automatisch/types'; import { IField, IGlobalVariable } from '@automatisch/types';
import { URLSearchParams } from 'url'; import { URLSearchParams } from 'url';
export default async function createAuthData($: IGlobalVariable) { export default async function createAuthData($: IGlobalVariable) {
@@ -20,12 +20,8 @@ export default async function createAuthData($: IGlobalVariable) {
accessSecret: responseData.oauth_token_secret, accessSecret: responseData.oauth_token_secret,
}); });
} catch (error) { } catch (error) {
const errorMessages = error.response.data.errors
.map((error: IJSONObject) => error.message)
.join(' ');
throw new Error( throw new Error(
`Error occured while verifying credentials: ${errorMessages}` `Error occured while verifying credentials: ${error.message}`
); );
} }
} }

View File

@@ -2,7 +2,6 @@ import { IGlobalVariable } from '@automatisch/types';
import { URLSearchParams } from 'url'; import { URLSearchParams } from 'url';
const verifyCredentials = async ($: IGlobalVariable) => { const verifyCredentials = async ($: IGlobalVariable) => {
try {
const response = await $.http.post( const response = await $.http.post(
`/oauth/access_token?oauth_verifier=${$.auth.data.oauthVerifier}&oauth_token=${$.auth.data.accessToken}`, `/oauth/access_token?oauth_verifier=${$.auth.data.oauthVerifier}&oauth_token=${$.auth.data.accessToken}`,
null null
@@ -18,9 +17,6 @@ const verifyCredentials = async ($: IGlobalVariable) => {
userId: responseData.user_nsid, userId: responseData.user_nsid,
screenName: responseData.fullname, screenName: responseData.fullname,
}); });
} catch (error) {
throw new Error(error.response.data);
}
}; };
export default verifyCredentials; export default verifyCredentials;

View File

@@ -2,7 +2,6 @@ import { IGlobalVariable } from '@automatisch/types';
import getCurrentUser from '../common/get-current-user'; import getCurrentUser from '../common/get-current-user';
const verifyCredentials = async ($: IGlobalVariable) => { const verifyCredentials = async ($: IGlobalVariable) => {
try {
const response = await $.http.post( const response = await $.http.post(
`${$.app.baseUrl}/login/oauth/access_token`, `${$.app.baseUrl}/login/oauth/access_token`,
{ {
@@ -32,9 +31,6 @@ const verifyCredentials = async ($: IGlobalVariable) => {
userId: currentUser.id, userId: currentUser.id,
screenName: currentUser.login, screenName: currentUser.login,
}); });
} catch (error) {
throw new Error(error.response.data);
}
}; };
export default verifyCredentials; export default verifyCredentials;

View File

@@ -3,7 +3,6 @@ import getCurrentUser from '../common/get-current-user';
import qs from 'qs'; import qs from 'qs';
const verifyCredentials = async ($: IGlobalVariable) => { const verifyCredentials = async ($: IGlobalVariable) => {
try {
const oauthRedirectUrlField = $.app.auth.fields.find( const oauthRedirectUrlField = $.app.auth.fields.find(
(field) => field.key == 'oAuthRedirectUrl' (field) => field.key == 'oAuthRedirectUrl'
); );
@@ -33,9 +32,6 @@ const verifyCredentials = async ($: IGlobalVariable) => {
await $.auth.set({ await $.auth.set({
screenName: `${currentUser.displayName} - ${data.instance_url}`, screenName: `${currentUser.displayName} - ${data.instance_url}`,
}); });
} catch (error) {
throw new Error(error.response.data);
}
}; };
export default verifyCredentials; export default verifyCredentials;

View File

@@ -1,15 +1,11 @@
import { IGlobalVariable } from '@automatisch/types'; import { IGlobalVariable } from '@automatisch/types';
const verifyCredentials = async ($: IGlobalVariable) => { const verifyCredentials = async ($: IGlobalVariable) => {
try {
await $.http.get('/2010-04-01/Accounts.json?PageSize=1'); await $.http.get('/2010-04-01/Accounts.json?PageSize=1');
await $.auth.set({ await $.auth.set({
screenName: $.auth.data.accountSid, screenName: $.auth.data.accountSid,
}); });
} catch (error) {
throw new Error(JSON.stringify(error.response.data));
}
}; };
export default verifyCredentials; export default verifyCredentials;

View File

@@ -2,7 +2,6 @@ import { IGlobalVariable } from '@automatisch/types';
import { URLSearchParams } from 'url'; import { URLSearchParams } from 'url';
const verifyCredentials = async ($: IGlobalVariable) => { const verifyCredentials = async ($: IGlobalVariable) => {
try {
const response = await $.http.post( const response = await $.http.post(
`/oauth/access_token?oauth_verifier=${$.auth.data.oauthVerifier}&oauth_token=${$.auth.data.accessToken}`, `/oauth/access_token?oauth_verifier=${$.auth.data.oauthVerifier}&oauth_token=${$.auth.data.accessToken}`,
null null
@@ -16,9 +15,6 @@ const verifyCredentials = async ($: IGlobalVariable) => {
userId: responseData.user_id, userId: responseData.user_id,
screenName: responseData.screen_name, screenName: responseData.screen_name,
}); });
} catch (error) {
throw new Error(error.response.data);
}
}; };
export default verifyCredentials; export default verifyCredentials;