Answer the question
In order to leave comments, you need to log in
Error forwarding up node js?
I have the main file and in it
In the router I have
app.use('/', router);
import {NextFunction, Request, Response} from "express";
import {sendHttpRequest} from "../../../projects/server/http-request";
import router from "../../../projects/routes";
router.get('/', ( async (req: Request, res: Response, next: NextFunction) => {
try {
let contractId = req.query.contractId;
const err = await sendHttpRequest(contractId, token);
res.send(err).end();
}
catch (e) {
next(e)
}
}));
export const sendHttpRequest = async (id: string, token: string) => {
try {
await getProductId(id, token);
return getContractData(id, token);
}
catch (e) {
console.error(e.message)
}
};
async function getProductId(id, token) {
try {
const variables = {};
const options = {};
const req = await fetch(url, options);
const res = await req.json();
if (res.data.entityObject.Produkt) {
idProduct = res.data.entityObject.Produkt.ID
} else {
// как прокинуть ошибку вверх?
}
}
catch (e) {
console.error(e.message)
}
}
Answer the question
In order to leave comments, you need to log in
export const sendHttpRequest = async (id: string, token: string) => {
try {
await getProductId(id, token);
return getContractData(id, token);
}
catch (e) {
console.error(e.message);
throw e;
}
};
async function getProductId(id, token) {
try {
const variables = {};
const options = {};
const req = await fetch(url, options);
const res = await req.json();
if (res.data.entityObject.Produkt) {
idProduct = res.data.entityObject.Produkt.ID;
} else {
throw new Error('Some error ...');
// Или же: return Promise.reject(new Error('Some error ...'));
}
}
catch (e) {
console.error(e.message);
throw e;
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question