ZippidyZap
ZippidyZap10mo ago

How to view console logs

I am getting an error Unexpected token N in JSON at position 0, which I'm expecting means its getting null or something like that back, but I'm not getting any of my console logs to find where the error is happening. How can step by step view where the issue is?
4 Replies
ZippidyZap
ZippidyZapOP10mo ago
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
};
}
}
vaibhav
vaibhav10mo ago
you need to use logging.log instead of console.log
ZippidyZap
ZippidyZapOP10mo ago
logging.log throws an error: logging is not defined
Gaurav Chadha
Gaurav Chadha10mo ago
@ZippidyZap You can define logging in the function decleration as a parameter. Docs - https://docs.buildship.com/logging#via-logging-statements-in-node-logic.
Logging – BuildShip
A unified resource to start building your backend with low-code. Dive into triggers, nodes, and step-by-step guidance to jumpstart your workflow creation.