TASK22229: pilot shared relay forwarding utility
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
import axios from "axios";
|
||||
import { azureHeaders } from "../../../actions/core/headers";
|
||||
import { consoleLogger } from "../../../actions/core/logger";
|
||||
import { getToken } from "../../../actions/core/token";
|
||||
import { hashAPIPath } from "../../../actions/core/hash";
|
||||
import { respondError, respondSuccess } from "./apiResponse";
|
||||
|
||||
const WEBAPI_URL =
|
||||
process.env.RELAY_ROOT ||
|
||||
"https://dev-pedw-ns.servicebus.windows.net/dev-pedw-hc/";
|
||||
|
||||
export const relayGet = async ({
|
||||
queryUrl,
|
||||
res,
|
||||
errorResponse,
|
||||
transformData
|
||||
}) => {
|
||||
try {
|
||||
const token = await getToken();
|
||||
const { data } = await axios.get(
|
||||
WEBAPI_URL + queryUrl + hashAPIPath(queryUrl),
|
||||
azureHeaders(token.access_token)
|
||||
);
|
||||
|
||||
return respondSuccess(
|
||||
res,
|
||||
typeof transformData === "function" ? transformData(data) : data
|
||||
);
|
||||
} catch (error) {
|
||||
consoleLogger(error);
|
||||
return respondError(res, errorResponse);
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user