[SOLVED] Moralis cloud function error

I made a cloud function word for word as per this video

When I try to run it, I run into this error

I don’t see the error, did you include it?

yes. I tried as a gist. Here is the error

|2021-10-09T18:51:13.253Z - Error: [object Object]|
||at Object.resolveError (/moralis-server/lib/triggers.js:631:17)|
||at error (/moralis-server/lib/Routers/FunctionsRouter.js:107:32)|
||at runMicrotasks ()|
||at processTicksAndRejections (internal/process/task_queues.js:95:5)|
||2021-10-09T18:51:13.250Z - Failed running cloud function getNFT for user undefined with:|
||Input: {"_ApplicationId":“EcXFhXVLhnGqUZNx9h8IyhtbZfwZCHYKbyIIlcZ3”,“nftId”:“0”}|
||Error: {“message”:{“status”:404,“headers”:{“date”:“Sat, 09 Oct 2021 18:51:13 GMT”,“content-type”:“text/html”,“transfer-encoding”:“chunked”,“connection”:“close”,“cf-cache-status”:“DYNAMIC”,“expect-ct”:“max-age=604800, report-uri=“https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct””,“report-to”:"{“endpoints”:[{“url”:“https:\/\/a.nel.cloudflare.com\/report\/v3?s=VnXhR0xhgYARcCtjx3lxlW4sbcgOCbhy6nnPYJtPnuC4e2BFeSGWdppTx8oBXJJ7Vk2FrgjGRMREdUfQyhcZMtrtN8sdx4NaohMNwy3i%2BWZkeMPwXDnoxE3pMFTym%2FCrQabu6HMozC7nQYVrh4k%3D”}],“group”:“cf-nel”,“max_age”:604800}",“nel”:"{“success_fraction”:0,“report_to”:“cf-nel”,“max_age”:604800}",“server”:“cloudflare”,“cf-ray”:“69b9cc8faf03fa48-AMS”},“buffer”:{“type”:“Buffer”,“data”:[60,104,116,109,108,62,13,10,60,104,101,97,100,62,60,116,105,116,108,101,62,52,48,52,32,78,111,116,32,70,111,117,110,100,60,47,116,105,116,108,101,62,60,47,104,101,97,100,62,13,10,60,98,111,100,121,62,13,10,60,99,101,110,116,101,114,62,60,104,49,62,52,48,52,32,78,111,116,32,70,111,117,110,100,60,47,104,49,62,60,47,99,101,110,116,101,114,62,13,10,60,104,114,62,60,99,101,110,116,101,114,62,110,103,105,110,120,47,49,46,49,56,46,48,32,40,85,98,117,110,116,117,41,60,47,99,101,110,116,101,114,62,13,10,60,47,98,111,100,121,62,13,10,60,47,104,116,109,108,62,13,10]},“text”:"\r\n404 Not Found\r\n\r\n

404 Not Found

\r\n
nginx/1.18.0 (Ubuntu)\r\n\r\n\r\n"},“code”:141}|

it looks like that error says:

<html>
<head><title>404 Not Found</title></head>
<body>
<center><h1>404 Not Found</h1></center>
<hr><center>nginx/1.18.0 (Ubuntu)</center>
</body>
</html>

No please see this

yes, that entire error looks to say that it was a not found error somewhere, maybe the cloud function tried to read a url

Moralis.Cloud.define(“getNFT”, async(request) => {
const logger = Moralis.Cloud.getLogger()

let NFTId = request.params.nftId;
let hexId = parseInt(NFTId).toString(16);
let paddedHex= (“0000000000000000000000000000000000000000000000000000000000000000” + hexId).slice(-64)
logger.info(paddedHex);
return Moralis.Cloud.httpRequest({url: “https://cr7ge1kve9u7.moralishost.com/{id}.json” + paddedHex + “.json”})
.then(function(httpResponse){
return httpResponse.text;
})
})

This is the function. It was working before

is that url accessible now?
what link you try to access there?

https://cr7ge1kve9u7.moralishost.com/0000000000000000000000000000000000000000000000000000000000000000.json

yes it works

I corrected this line
return Moralis.Cloud.httpRequest({url: “https://cr7ge1kve9u7.moralishost.com/{id}.json” + paddedHex + “.json”})

It is supposed to be

return Moralis.Cloud.httpRequest({url: “https://cr7ge1kve9u7.moralishost.com/” + paddedHex + “.json”})

Still saying not found

you can log that url before trying to access it, to make sure has the right value

i did logger.info(httpResponse) but the same output even after restarting the server

2021-10-09T20:12:46.164Z - Error: [object Object]
at Object.resolveError (/moralis-server/lib/triggers.js:631:17)
at error (/moralis-server/lib/Routers/FunctionsRouter.js:107:32)
at processTicksAndRejections (internal/process/task_queues.js:95:5)
2021-10-09T20:12:46.157Z - Failed running cloud function getNFT for user undefined with:
Input: {"_ApplicationId":“EcXFhXVLhnGqUZNx9h8IyhtbZfwZCHYKbyIIlcZ3”,“nftId”:“1”}
Error: {“message”:{“status”:404,“headers”:{“date”:“Sat, 09 Oct 2021 20:12:46 GMT”,“content-type”:“text/html”,“transfer-encoding”:“chunked”,“connection”:“close”,“cf-cache-status”:“DYNAMIC”,“expect-ct”:“max-age=604800, report-uri=“https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct””,“report-to”:"{“endpoints”:[{“url”:“https:\/\/a.nel.cloudflare.com\/report\/v3?s=d3laPWLOQ5H2QQMHRqhA9Rl6A45muB4k8MRJxAEkUJchxsoUNpkBE0l5j9lFtqemK7UnFeviT6u56AssboN7Uf3WPE%2FnSHmUGA%2Btf305Z1PmvsAr6rWlwF4KFiS01m01wsy%2FZQNwN8pLbGSJOHo%3D”}],“group”:“cf-nel”,“max_age”:604800}",“nel”:"{“success_fraction”:0,“report_to”:“cf-nel”,“max_age”:604800}",“server”:“cloudflare”,“cf-ray”:“69ba44044b231e81-AMS”},“buffer”:{“type”:“Buffer”,“data”:[60,104,116,109,108,62,13,10,60,104,101,97,100,62,60,116,105,116,108,101,62,52,48,52,32,78,111,116,32,70,111,117,110,100,60,47,116,105,116,108,101,62,60,47,104,101,97,100,62,13,10,60,98,111,100,121,62,13,10,60,99,101,110,116,101,114,62,60,104,49,62,52,48,52,32,78,111,116,32,70,111,117,110,100,60,47,104,49,62,60,47,99,101,110,116,101,114,62,13,10,60,104,114,62,60,99,101,110,116,101,114,62,110,103,105,110,120,47,49,46,49,56,46,48,32,40,85,98,117,110,116,117,41,60,47,99,101,110,116,101,114,62,13,10,60,47,98,111,100,121,62,13,10,60,47,104,116,109,108,62,13,10]},“text”:"\r\n404 Not Found\r\n\r\n

404 Not Found

\r\n
nginx/1.18.0 (Ubuntu)\r\n\r\n\r\n"},“code”:141}

How do i clear the moralis log?

you should log the parameter to Moralis.Cloud.httpRequest, to see what it tries to access there

the response to Moralis.Cloud.httpRequest is httpResponse correct?

logger.info(Moralis.Cloud.httpRequest)?

How do i clear the Moralis log, the same error has come up and the time zone is different from where I stay to the point I cannot make out if it is the latest error or no log

I think it ran once correctly

2021-10-09T20:23:51.296Z - Error: [object Object]
at Object.resolveError (/moralis-server/lib/triggers.js:631:17)
at error (/moralis-server/lib/Routers/FunctionsRouter.js:107:32)
at runMicrotasks ()
at processTicksAndRejections (internal/process/task_queues.js:95:5)
2021-10-09T20:23:51.291Z - Failed running cloud function getNFT for user undefined with:
Input: {"_ApplicationId":“EcXFhXVLhnGqUZNx9h8IyhtbZfwZCHYKbyIIlcZ3”,“nftId”:“1”}
Error: {“message”:{“status”:404,“headers”:{“date”:“Sat, 09 Oct 2021 20:23:51 GMT”,“content-type”:“text/html”,“transfer-encoding”:“chunked”,“connection”:“close”,“cf-cache-status”:“DYNAMIC”,“expect-ct”:“max-age=604800, report-uri=“https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct””,“report-to”:"{“endpoints”:[{“url”:“https:\/\/a.nel.cloudflare.com\/report\/v3?s=giw7SQKxxwy2TVVc3EzQPv%2B6O3vanmUETSJk4oN8oMW6D0liYLDgNd1JR9XMsBhb2y9zWuJ32V%2BrVyE5ODzfxqeakZnWv2vjptEb8Q%2B7nw5%2Bl2lIEPLngyxj6MiSEt2VYl99qhQgWra2b2HKpa0%3D”}],“group”:“cf-nel”,“max_age”:604800}",“nel”:"{“success_fraction”:0,“report_to”:“cf-nel”,“max_age”:604800}",“server”:“cloudflare”,“cf-ray”:“69ba54416c8741ce-AMS”},“buffer”:{“type”:“Buffer”,“data”:[60,104,116,109,108,62,13,10,60,104,101,97,100,62,60,116,105,116,108,101,62,52,48,52,32,78,111,116,32,70,111,117,110,100,60,47,116,105,116,108,101,62,60,47,104,101,97,100,62,13,10,60,98,111,100,121,62,13,10,60,99,101,110,116,101,114,62,60,104,49,62,52,48,52,32,78,111,116,32,70,111,117,110,100,60,47,104,49,62,60,47,99,101,110,116,101,114,62,13,10,60,104,114,62,60,99,101,110,116,101,114,62,110,103,105,110,120,47,49,46,49,56,46,48,32,40,85,98,117,110,116,117,41,60,47,99,101,110,116,101,114,62,13,10,60,47,98,111,100,121,62,13,10,60,47,104,116,109,108,62,13,10]},“text”:"\r\n404 Not Found\r\n\r\n

404 Not Found

\r\n
nginx/1.18.0 (Ubuntu)\r\n\r\n\r\n"},“code”:141}
2021-10-09T20:23:51.275Z - Ran cloud function getNFT for user undefined with:
Input: {"_ApplicationId":“EcXFhXVLhnGqUZNx9h8IyhtbZfwZCHYKbyIIlcZ3”,“nftId”:“0”}
Result: {“status”:200,“headers”:{“date”:“Sat, 09 Oct 2021 20:23:51 GMT”,“content-type”:“application/json”,“content-length”:“138”,“connection”:“close”,“last-modified”:“Tue, 05 Oct 2021 12:11:33 GMT”,“etag”:"“615c40f5-8a”",“accept-ranges”:“bytes”,“cf-cache-status”:“DYNAMIC”,“expect-ct”:“max-age=604800, report-uri=“https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct””,“report-to”:"{“endpoints”:[{“url”:“https:\/\/a.nel.cloudflare.com\/report\/v3?s=TmmCLAWpZ93QRlDHkZrpOFpW97KjGwwGlWGjU%2ByTKJVyAzYLA%2Bm22O4KkRH%2FH4O0dS9FvBriCZPRbxq%2FKxFGeDPjX2KH9%2FIfZGqiDLq7PSd2cKa%2BbK4Y%2FWXKUL1cZ8sOm76OGIYh4lG12VcP7ZU%3D”}],“group”:“cf-nel”,“max_age”:604800}",“nel”:"{“success_fraction”:0,“report_to”:“cf-nel”,“max_age”:604800}",“server”:“cloudflare”,“cf-ray”:“69ba544158744c3e-AMS”},“buffer”:{“type”:“Buffer”,“data”:[]},“text”:"{\n “image”:“https://xvndizkxt57v.moralisweb3.com/ngannou.png”,\n “description”:“ngannou vs jones”,\n “name”:“Ngannou V Jones FR”\n… (truncated)

I mean, instead of doing:

return Moralis.Cloud.httpRequest({url: “https://cr7ge1kve9u7.moralishost.com/” + paddedHex + “.json”})

you should do:

x = “https://cr7ge1kve9u7.moralishost.com/” + paddedHex + “.json”
logger.info(x);
return Moralis.Cloud.httpRequest({url: x})

so that you see what url it tries to access there.

yep, it looks like it run ok once from that log

why did it stop again ? I didnt change anything

I don’t know, do you also send parameters to that cloud function? maybe only some ids work

how to clear the moralis log?