Site - selftaught-dev.com
Site ID - happy-hugle-97373a
For some reason I’m gettinng a "TypeError: n is not a function"
I’ve narrowed it down to this line const result = faunaFetch({ query, variables })
through adding console logs before/after it. Is there anything glaringly wrong with that line, or in the faunaFetch function?
Full Function Below
const stripe = require("stripe")(process.env.STRIPE_SECRET_KEY)
const fetch = require("node-fetch")
exports.handler = async (event, context) => {
const { user } = context.clientContext
const faunaFetch = async ({ query, variables }) => {
return await fetch("https://graphql.fauna.com/graphql", {
method: "POST",
headers: {
Authorization: `Bearer ${process.env.FAUNA_SERVER_KEY}`,
},
body: JSON.stringify({
query,
variables,
}),
})
.then(res => res.json())
.catch(err => console.error(JSON.stringify(err, null, 2)))
}
const query = `
query ($netlifyID: ID!) {
getUserByNetlifyID(netlifyID: $netlifyID){
stripeID
netlifyID
}
}
`
const variables = { netlifyID: user.sub }
const result = faunaFetch({ query, variables })
console.log(JSON.stringify(result))
// console.log(stripeID)
return {
statusCode: 200,
body: JSON.stringify(result),
}
}
Function Log
8:51:11 AM: 2020-10-24T13:51:11.978Z 305c10be-c371-40c2-bd43-be0553b9573c ERROR Unhandled Promise Rejection {"errorType":"Runtime.UnhandledPromiseRejection","errorMessage":"TypeError: n is not a function","reason":{"errorType":"TypeError","errorMessage":"n is not a function","stack":["TypeError: n is not a function"," at /var/task/src/create-manage-link.js:1:70055"," at Runtime.t.handler (/var/task/src/create-manage-link.js:1:70284)"," at Runtime.handleOnce (/var/runtime/Runtime.js:66:25)"]},"promise":{},"stack":["Runtime.UnhandledPromiseRejection: TypeError: n is not a function"," at process.<anonymous> (/var/runtime/index.js:35:15)"," at process.emit (events.js:315:20)"," at processPromiseRejections (internal/process/promises.js:209:33)"," at processTicksAndRejections (internal/process/task_queues.js:98:32)"]}
8:51:11 AM: [ERROR] [1603547471979] LAMBDA_RUNTIME Failed to post handler success response. Http response code: 403.
8:51:11 AM: Duration: 7.52 ms Memory Usage: 67 MB Init Duration: 187.74 ms
8:51:11 AM: RequestId: 305c10be-c371-40c2-bd43-be0553b9573c Error: Runtime exited with error: exit status 128
Runtime.ExitError
Repo
Function is in src → functions → create-manage-link.js