import { HttpError } from 'wasp/server'
const fetchExternalData = async (tokenUrl, headers) => {
try {
const response = await axios.post(tokenUrl, {}, { headers });
return response.data;
} catch (error) {
if (error.response && error.response.status === 401) {
throw new Error('Bad Credentials');
}
throw error;
}
}
export const yourExportedAction = async (args, context) => {
try {
const data = await fetchExternalData(args.tokenUrl, args.headers);
// Process data
return data;
} catch (error) {
if (error.message === 'Bad Credentials') {
throw new HttpError(401, 'Bad Credentials');
}
// Handle other errors
throw new HttpError(500, 'An unexpected error occurred');
}
}
import { HttpError } from 'wasp/server'
const fetchExternalData = async (tokenUrl, headers) => {
try {
const response = await axios.post(tokenUrl, {}, { headers });
return response.data;
} catch (error) {
if (error.response && error.response.status === 401) {
throw new Error('Bad Credentials');
}
throw error;
}
}
export const yourExportedAction = async (args, context) => {
try {
const data = await fetchExternalData(args.tokenUrl, args.headers);
// Process data
return data;
} catch (error) {
if (error.message === 'Bad Credentials') {
throw new HttpError(401, 'Bad Credentials');
}
// Handle other errors
throw new HttpError(500, 'An unexpected error occurred');
}
}