#Arctic

1 messages · Page 1 of 1 (latest)

upbeat kayakBOT
wild adder
#

👋 happy to help

#

have you changed the API keys to live mode keys?

wicked pecan
#

no its still test mode

wild adder
#

what is the error you're getting?

wicked pecan
#
[POST] /api/products/stripe-products
11:38:27:78
2022-11-23T10:38:28.192Z    e6895a82-1d85-4cce-9e39-7a30ce0feae5    ERROR    Uncaught Exception     {"errorType":"Error","errorMessage":"write after end","code":"ERR_STREAM_WRITE_AFTER_END","stack":["Error [ERR_STREAM_WRITE_AFTER_END]: write after end","    at new NodeError (node:internal/errors:372:5)","    at ServerResponse.end (node:_http_outgoing:846:15)","    at ServerResponse.apiRes.end (/var/task/node_modules/next/dist/server/api-utils/node.js:346:25)","    at handler (/var/task/.next/server/pages/api/products/stripe-products.js:67:29)","    at processTicksAndRejections (node:internal/process/task_queues:96:5)","    at async Object.apiResolver (/var/task/node_modules/next/dist/server/api-utils/node.js:366:9)","    at async NextNodeServer.runApi (/var/task/node_modules/next/dist/server/next-server.js:481:9)","    at async Object.fn (/var/task/node_modules/next/dist/server/next-server.js:735:37)","    at async Router.execute (/var/task/node_modules/next/dist/server/router.js:247:36)","    at async NextNodeServer.run (/var/task/node_modules/next/dist/server/base-server.js:347:29)"]}
Unknown application error occurred
Runtime.Unknown
#

this is from my vercel logs

#

where can i find the stripe error? in my stripe logs theres no error

wild adder
#

would you mind sharing the code of your /api/products/stripe-products route

wicked pecan
#

okay, one sec

#

hello?

#

oh

#

i think the file is too long

#

sec

#

this is the relevant part ```js
(req.body?.call === "create-product") {
const product = await stripe.products.create({
name: req.body.data.name,
active: req.body.data.active,
description: req.body.data.description,
})
res.status(200).send(product)
}

wild adder
#

would you mind adding some logs so we know at which point the function is failing?

wicked pecan
#

okay, i gotta talk to some customers, im at work give me few mins

wild adder
#

sure thing

wicked pecan
#
if (req.body?.call === "create-product") {
const product = await stripe.products.create({
name: req.body.data.name,
active: req.body.data.active,
description: req.body.data.description,
})
console.log(product)
res.status(200).send(product)
}
#

its logging the product

#

and then throwing the error

#
[POST] /api/products/stripe-products
12:09:39:87
{
  id: 'prod_MqynLEAd0JlDPN',
  object: 'product',
  active: true,
  attributes: [],
  created: 1669201780,
  default_price: null,
  description: 'ad',
  images: [],
  livemode: false,
  metadata: {},
  name: 'sd',
  package_dimensions: null,
  shippable: null,
  statement_descriptor: null,
  tax_code: null,
  type: 'service',
  unit_label: null,
  updated: 1669201780,
  url: null
}
2022-11-23T11:09:40.272Z    b660c3b4-79d2-4c44-8321-715c49809800    ERROR    Uncaught Exception     {"errorType":"Error","errorMessage":"write after end","code":"ERR_STREAM_WRITE_AFTER_END","stack":["Error [ERR_STREAM_WRITE_AFTER_END]: write after end","    at new NodeError (node:internal/errors:372:5)","    at ServerResponse.end (node:_http_outgoing:846:15)","    at ServerResponse.apiRes.end (/var/task/node_modules/next/dist/server/api-utils/node.js:346:25)","    at handler (/var/task/.next/server/pages/api/products/stripe-products.js:68:29)","    at processTicksAndRejections (node:internal/process/task_queues:96:5)","    at async Object.apiResolver (/var/task/node_modules/next/dist/server/api-utils/node.js:366:9)","    at async NextNodeServer.runApi (/var/task/node_modules/next/dist/server/next-server.js:481:9)","    at async Object.fn (/var/task/node_modules/next/dist/server/next-server.js:735:37)","    at async Router.execute (/var/task/node_modules/next/dist/server/router.js:247:36)","    at async NextNodeServer.run (/var/task/node_modules/next/dist/server/base-server.js:347:29)"]}
Unknown application error occurred
Runtime.Unknown
wild adder
#

would you mind trying res.status(200).send(JSON.stringify(product))

#

OHHHHHH

#

wait wait

#

my bad!

#

you should return so that the function doesn't continue executing

#

return res.status(200).send(product);

wicked pecan
#

ohh wtf, should i always do that? o.o

#

i thought if i send a response the function stops executing

wild adder
#

yes otherwise, you might hit another res.send which basically is what this "ERR_STREAM_WRITE_AFTER_END" is about

wicked pecan
#

ohh okay thanks, ill put this in my other functions aswell

wild adder
#

nop you wrote to the STREAM but you haven't stopped executing the function

wicked pecan
#

okaaay, thx

#

ill try it now

wicked pecan
#

fixxed it

#

thank you:)

runic fable
#

Hey, taking over here. Let me know if there's any follow-up Qs I can answer!