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';
export default async function createAuthData($: IGlobalVariable) {
@@ -20,12 +20,8 @@ export default async function createAuthData($: IGlobalVariable) {
accessSecret: responseData.oauth_token_secret,
});
} catch (error) {
const errorMessages = error.response.data.errors
.map((error: IJSONObject) => error.message)
.join(' ');
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';
const verifyCredentials = async ($: IGlobalVariable) => {
try {
const response = await $.http.post(
`/oauth/access_token?oauth_verifier=${$.auth.data.oauthVerifier}&oauth_token=${$.auth.data.accessToken}`,
null
@@ -18,9 +17,6 @@ const verifyCredentials = async ($: IGlobalVariable) => {
userId: responseData.user_nsid,
screenName: responseData.fullname,
});
} catch (error) {
throw new Error(error.response.data);
}
};
export default verifyCredentials;

View File

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

View File

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

View File

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

View File

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