This works locally on netlify dev, I still get the first Buffer() depreciation warning, but when I push it to production it completely breaks.
I first get this error:
ERROR (node:7) [DEP0005] DeprecationWarning: Buffer() is deprecated due to security and usability issues. Please use the Buffer.alloc(), Buffer.allocUnsafe(), or Buffer.from() methods instead.
1:34:02 PM: Duration: 1831.45 ms Memory Usage: 18 MB
and then:
unhandled Promise Rejection {"errorType":"Runtime.UnhandledPromiseRejection","errorMessage":"FetchError: request to https://db.fauna.com/ failed, reason: Client network socket disconnected before secure TLS connection was established","reason":{"errorType":"FetchError","errorMessage":"request to https://db.fauna.com/ failed, reason: Client network socket disconnected before secure TLS connection was established","code":"ECONNRESET","message":"request to https://db.fauna.com/ failed, reason: Client network socket disconnected before secure TLS connection was established","type":"system","errno":"ECONNRESET","stack":["FetchError: request to https://db.fauna.com/ failed, reason: Client network socket disconnected before secure TLS connection was established"," at ClientRequest.<anonymous> (/var/task/src/built-lambda/reservation-create.js:6:31572)"," at ClientRequest.emit (events.js:310:20)"," at TLSSocket.socketErrorListener (_http_client.js:426:9)"," at TLSSocket.emit (events.js:310:20)"," at emitErrorNT (internal/streams/destroy.js:92:8)"," at emitErrorAndCloseNT (internal/streams/destroy.js:60:3)"," at processTicksAndRejections (internal/process/task_queues.js:84:21)"]},"promise":{},"stack":
["Runtime.UnhandledPromiseRejection: FetchError: request to https://db.fauna.com/ failed, reason: Client network socket disconnected before secure TLS connection was established"," at process.<anonymous> (/var/runtime/index.js:35:15)"," at process.emit (events.js:310:20)"," at processPromiseRejections (internal/process/promises.js:209:33)"," at processTicksAndRejections (internal/process/task_queues.js:98:32)"]}
followed by:
[ERROR] [1591130035553] LAMBDA_RUNTIME Failed to post handler success response. Http response code: 403.
Here’s my code:
const faunadb = require('faunadb');
const q = faunadb.query;
exports.handler = async (event, context, callback) => {
try {
const client = new faunadb.Client({
secret: process.env.SECRET
});
const reservation = JSON.parse(event.body);
let reservationBlockRef =
reservation.reservationBlock?.reservationBlock?.ref?.['@ref']?.id;
// double check here to see if a reservation block exists
if (!reservationBlockRef) {
const { data } = await client.query(
// query
);
for (let block of data) {
if (
block.data.start_time === reservation.start &&
block.data.end_time === reservation.end
) {
reservationBlockRef = block.ref.id;
}
}
}
// if it really doesn't exist at this point, we're creating one
if (!reservationBlockRef) {
const response = await client.query(
// query
);
return new Promise(resolve =>
resolve({
headers: {
'Access-Control-Allow-Origin': '*'
},
statusCode: 200,
body: JSON.stringify(response)
})
);
}
const res = client.query(
// query
);
return new Promise(resolve =>
resolve({
headers: {
'Access-Control-Allow-Origin': '*'
},
statusCode: 200,
body: JSON.stringify(res)
})
);
} catch (error) {
return new Promise(resolve =>
resolve({
headers: {
'Access-Control-Allow-Origin': '*'
},
statusCode: 400,
body: JSON.stringify(error)
})
);
}
};
Does anyone know what I’m doing wrong?