ZippidyZap
BRBuildShip + Rowy
•Created by ZippidyZap on 2/13/2024 in #❓・buildship-help
How to view console logs
logging.log throws an error: logging is not defined
5 replies
BRBuildShip + Rowy
•Created by ZippidyZap on 2/13/2024 in #❓・buildship-help
How to view console logs
import fetch from "node-fetch";
export default async function apiCall({
url,
method,
contentType,
authorization,
body,
shouldAwait,
queryParams
}, {
logging
}) {
const headers = {
"Content-Type": contentType
};
if (authorization) headers["Authorization"] = authorization;
let queryParamsString = '';
if (queryParams) {
queryParamsString = '/' + queryParams;
console.log(queryParamsString)
}
const fetchOptions = {
method,
headers
};
if (method !== 'GET') {
fetchOptions.body = JSON.stringify(body);
}
console.log(url + queryParamsString)
const fetchPromise = fetch(url + queryParamsString, fetchOptions);
if (!shouldAwait) {
return {
data: null
};
}
const response = await fetchPromise;
const data = await response.json();
// Check if data.sprites and data.sprites.front_default exist
const frontDefault = data.sprites?.front_default;
if (frontDefault) {
return {
status: response.status,
data: frontDefault
};
}
}
import fetch from "node-fetch";
export default async function apiCall({
url,
method,
contentType,
authorization,
body,
shouldAwait,
queryParams
}, {
logging
}) {
const headers = {
"Content-Type": contentType
};
if (authorization) headers["Authorization"] = authorization;
let queryParamsString = '';
if (queryParams) {
queryParamsString = '/' + queryParams;
console.log(queryParamsString)
}
const fetchOptions = {
method,
headers
};
if (method !== 'GET') {
fetchOptions.body = JSON.stringify(body);
}
console.log(url + queryParamsString)
const fetchPromise = fetch(url + queryParamsString, fetchOptions);
if (!shouldAwait) {
return {
data: null
};
}
const response = await fetchPromise;
const data = await response.json();
// Check if data.sprites and data.sprites.front_default exist
const frontDefault = data.sprites?.front_default;
if (frontDefault) {
return {
status: response.status,
data: frontDefault
};
}
}
5 replies