joetroll
joetroll
DIAdiscord.js - Imagine an app
Created by joetroll on 6/1/2024 in #djs-questions
HTTP Status code 400 [TypeScript]
Making a bot using typescript that fetches a specific api, then sends the info formatted into an embed. i first start off defining headers (don't worry, api key is public)
const options: RequestInit = {
method: 'POST',
headers: {
accept: 'application/json',
'Content-Type': 'application/json',
Authorization: 'Bearer e2a1974678b37386fef69bb3638a1fb36263b78a8be244c04795ada0fa250d3d'
},
body: JSON.stringify({ q: gameName, limit: 2, page: nextPage })
};
const options: RequestInit = {
method: 'POST',
headers: {
accept: 'application/json',
'Content-Type': 'application/json',
Authorization: 'Bearer e2a1974678b37386fef69bb3638a1fb36263b78a8be244c04795ada0fa250d3d'
},
body: JSON.stringify({ q: gameName, limit: 2, page: nextPage })
};
which, is basically the same code i've used for my other file, just without the "nextPage".
try {
const fetchPage = await fetch('(api link here)', options);
if (!fetchPage.ok) {
console.log(fetchPage)
console.log(nextPage)
throw new Error(`HTTP error status: ${fetchPage.status}`);
}
try {
const fetchPage = await fetch('(api link here)', options);
if (!fetchPage.ok) {
console.log(fetchPage)
console.log(nextPage)
throw new Error(`HTTP error status: ${fetchPage.status}`);
}
(don't mind the non existent api link, it's there in my code) this just prints out debug info, which, the nextPage looks fine, but the json response is wrong, returning a "[Symbol(realm)]: null,". i am using the meilisearch api to fetch stuff. but, still gives out http status code 400. my other code, that is basically the same thing, fetches just fine. is the issue within "nextPage"?
4 replies