Error 401 unauthorized - dialogflow-es

My bot was working perfectly until now, I am suddenly getting an error called Unauthorized from API.ai I checked my Heroku logs and this is what I found
Any ideas are appreciated
2018-08-18T14:27:59.087498+00:00 heroku[router]: at=info method=POST path="/api/messages" host=zupcoin.herokuapp.com request_id=7d2de5a3-05f8-414a-a28e-5cc3e43ab578 fwd="40.121.92.251" dyno=web.1 connect=1ms service=596ms status=202 bytes=199 protocol=https
{ Error
at IncomingMessage.<anonymous> (/app/node_modules/apiai/module/json_api_request.js:59:25)
at emitNone (events.js:110:20)
at IncomingMessage.emit (events.js:207:7)
at endReadableNT (_stream_readable.js:1045:12)
at _combinedTickCallback (internal/process/next_tick.js:138:11)
at process._tickCallback (internal/process/next_tick.js:180:9)
statusCode: 403,
responseBody: '{"status":{"code":401,"errorType":"unauthorized","errorDetails":"You are not authorized for this operation. Invalid access token"}}',
name: 'ServerError',
message: 'Wrong response status code.' }
Error
at IncomingMessage.<anonymous> (/app/node_modules/apiai/module/json_api_request.js:59:25)
at emitNone (events.js:110:20)
at IncomingMessage.emit (events.js:207:7)
at endReadableNT (_stream_readable.js:1045:12)
at _combinedTickCallback (internal/process/next_tick.js:138:11)
at process._tickCallback (internal/process/next_tick.js:180:9)

Related

Error [ERR_STREAM_WRITE_AFTER_END]: write after end ExpressJS

I forked a repo I found and running it locally was fine with no errors however I wanted to run it locally on https so I changed the code of src/index.js
const server = createServer();
to
const options = {
key: fs.readFileSync('localhost-key.pem'),
cert: fs.readFileSync('localhost.pem')
};
const server = https.createServer(options, app)
But I started getting the error after the change when I try to access the website on https://localhost:8080
Full Error:
node:events:491
throw er; // Unhandled 'error' event
^
Error [ERR_STREAM_WRITE_AFTER_END]: write after end
at new NodeError (node:internal/errors:399:5)
at write_ (node:_http_outgoing:868:11)
at ServerResponse.write (node:_http_outgoing:827:15)
at ReadStream.ondata (node:internal/streams/readable:766:22)
at ReadStream.emit (node:events:513:28)
at addChunk (node:internal/streams/readable:324:12)
at readableAddChunk (node:internal/streams/readable:297:9)
at Readable.push (node:internal/streams/readable:234:10)
at node:internal/fs/streams:275:14
at FSReqCallback.wrapper [as oncomplete] (node:fs:681:5)
Emitted 'error' event on ServerResponse instance at:
at ServerResponse.onerror (node:internal/streams/readable:785:14)
at ServerResponse.emit (node:events:525:35)
at emitErrorNt (node:_http_outgoing:846:9)
at process.processTicksAndRejections (node:internal/process/task_queues:83:21) {
code: 'ERR_STREAM_WRITE_AFTER_END'
}

Connection Terminated Connecting to Private Space Postgres from Inside Private Space

I'm attempting to display rows of data from a private space Postgres instance attached to app-a from another app - app-b, inside the same Private Space.
Running heroku local didn't work - which I thought was due to my personal IP not being whitelisted, so I pushed to app-b. I've also added the credential for app-b - to no avail. app-b has no DB of it's own and I've tried adding credential while DATABASE_URL is manually filled, and with no DATABASE_URL on abb-b - none of which worked.
I'm able to run heroku pg:psql from app-a but not from app-b, leading me to think the credential may not be attached/incorrectly attached?
My code is simple and shown below:
var { Client } = require('pg');
app.get('/db', (req, res) => {
var dbOpts = {
connectionString: process.env.DATABASE_URL,
ssl : {
rejectUnauthorized: false
}
}
const client = new Client(dbOpts);
client.connect();
client.query('SELECT FirstName, Id FROM salesforce.user', (err, dbRes) => {
console.log('inside');
if (err) {
console.log('DB Route err: ', err);
throw err;
}
console.log('dbRes: ', dbRes);
res.render('pages/db',{
results : dbRes.rows
});
});
client.end();
});
As soon as I hit /db the following error is thrown
2022-03-04T08:21:30.057536+00:00 app[web.1]: /app/index.js:25
2022-03-04T08:21:30.057537+00:00 app[web.1]: throw err;
2022-03-04T08:21:30.057537+00:00 app[web.1]: ^
2022-03-04T08:21:30.057537+00:00 app[web.1]:
2022-03-04T08:21:30.057537+00:00 app[web.1]: Error: Connection terminated
2022-03-04T08:21:30.057538+00:00 app[web.1]: at Connection.<anonymous> (/app/node_modules/pg/lib/client.js:132:36)
2022-03-04T08:21:30.057538+00:00 app[web.1]: at Object.onceWrapper (node:events:641:28)
2022-03-04T08:21:30.057538+00:00 app[web.1]: at Connection.emit (node:events:539:35)
2022-03-04T08:21:30.057539+00:00 app[web.1]: at Socket.<anonymous> (/app/node_modules/pg/lib/connection.js:57:12)
2022-03-04T08:21:30.057539+00:00 app[web.1]: at Socket.emit (node:events:527:28)
2022-03-04T08:21:30.057539+00:00 app[web.1]: at TCP.<anonymous> (node:net:688:12)
2022-03-04T08:21:30.057540+00:00 app[web.1]:
2022-03-04T08:21:30.057540+00:00 app[web.1]: Node.js v17.6.0
2022-03-04T08:21:30.055860+00:00 app[web.1]: inside
2022-03-04T08:21:30.057190+00:00 app[web.1]: DB Route err: Error: Connection terminated
2022-03-04T08:21:30.057191+00:00 app[web.1]: at Connection.<anonymous> (/app/node_modules/pg/lib/client.js:132:36)
2022-03-04T08:21:30.057192+00:00 app[web.1]: at Object.onceWrapper (node:events:641:28)
2022-03-04T08:21:30.057192+00:00 app[web.1]: at Connection.emit (node:events:539:35)
2022-03-04T08:21:30.057192+00:00 app[web.1]: at Socket.<anonymous> (/app/node_modules/pg/lib/connection.js:57:12)
2022-03-04T08:21:30.057193+00:00 app[web.1]: at Socket.emit (node:events:527:28)
2022-03-04T08:21:30.057193+00:00 app[web.1]: at TCP.<anonymous> (node:net:688:12)
2022-03-04T08:21:30.060340+00:00 heroku[router]: at=error code=H13 desc="Connection closed without response" method=GET path="/db" host=agdc-hconnect-view.herokuapp.com request_id=3e850bf1-c88a-68bc-6f21-0ef82b960ce9 fwd="75.111.73.234" dyno=web.1 connect=0ms service=19ms status=503 bytes=561 protocol=http tls_version=tls1.3
2022-03-04T08:21:30.659072+00:00 heroku[web.1]: Process exited with status 1
2022-03-04T08:21:30.679550+00:00 heroku[web.1]: State changed from up to crashed

NetworkingError AWS SES

I am sending emails using AWS SES. It was working fine, but recently I am getting Networking errors. Full stack track is as followling.
Error: write EPROTO 140495130142528:error:140770FC:SSL
routines:SSL23_GET_SERVER_HELLO:unknown
protocol:../deps/openssl/openssl/ssl/s23_clnt.c:827:
at _errnoException (util.js:1022:11)
at WriteWrap.afterWrite [as oncomplete] (net.js:880:14)
message: 'write EPROTO 140495130142528:error:140770FC:SSL
routines:SSL23_GET_SERVER_HELLO:unknown
protocol:../deps/openssl/openssl/ssl/s23_clnt.c:827:\n',
code: 'NetworkingError',
errno: 'EPROTO',
syscall: 'write',
region: 'us-east-1',
hostname: 'email.us-east-1.amazonaws.com',
retryable: true,
time: 2018-07-26T09:57:44.096Z
I am also getting following error.
TimeoutError: Connection timed out after 120000ms
at ClientRequest.<anonymous> (/var/runtime/node_modules/aws-
sdk/lib/http/node.js:83:34)
at Object.onceWrapper (events.js:313:30)
at emitNone (events.js:106:13)
at ClientRequest.emit (events.js:208:7)
at TLSSocket.emitTimeout (_http_client.js:711:34)
at Object.onceWrapper (events.js:313:30)
at emitNone (events.js:106:13)
at TLSSocket.emit (events.js:208:7)
at TLSSocket.Socket._onTimeout (net.js:420:8)
at ontimeout (timers.js:482:11)
message: 'Connection timed out after 120000ms',
code: 'TimeoutError',
time: 2018-07-26T10:09:31.149Z,
region: 'us-east-1',
hostname: 'email.us-east-1.amazonaws.com',
retryable: true
How to resolve this issue?

Can't set headers after they are sent when trying to redirect after using Google's oauth2Client.getToken()

After receiving oauth2 tokens from google I am trying to redirect to an endpoint on my express server to make api requests.
This is the flow of the auth requests:
app.get('/api/presentation/getpresentation/:id', function(req, res, next){
req.session.user = req.user.id;
req.session.presentation_id = req.params.id;
res.redirect(google_auth_url)
});
app.get('/oauth2callback', function(req, res) {
const code = req.query.code;
oauth2Client.getToken(code, function(err, tokens) {
req.session.tokens = tokens;
if (!err) {
oauth2Client.setCredentials(tokens);
res.redirect(`/api/presentation/${req.session.presentation_id}`);
return;
}
res.status(500).send(err);
})
});
app.get('/api/presentation/:id', **do things with api consent**);
The error:
Error: Can't set headers after they are sent.
at validateHeader (_http_outgoing.js:489:11)
at ServerResponse.setHeader (_http_outgoing.js:496:3)
at ServerResponse.header (/Users/joe/school/solo-project/present/node_modules/express/lib/response.js:767:10)
at ServerResponse.location (/Users/joe/school/solo-project/present/node_modules/express/lib/response.js:884:15)
at ServerResponse.redirect (/Users/joe/school/solo-project/present/node_modules/express/lib/response.js:922:18)
at /Users/joe/school/solo-project/present/server/index.js:112:11
at /Users/joe/school/solo-project/present/node_modules/google-auth-library/lib/auth/oauth2client.js:154:5
at Request._callback (/Users/joe/school/solo-project/present/node_modules/google-auth-library/lib/transporters.js:106:7)
at Request.self.callback (/Users/joe/school/solo-project/present/node_modules/request/request.js:186:22)
at emitTwo (events.js:125:13)
at Request.emit (events.js:213:7)
at Request.<anonymous> (/Users/joe/school/solo-project/present/node_modules/request/request.js:1163:10)
at emitOne (events.js:115:13)
at Request.emit (events.js:210:7)
at IncomingMessage.<anonymous> (/Users/joe/school/solo-project/present/node_modules/request/request.js:1085:12)
at Object.onceWrapper (events.js:314:30)
at emitNone (events.js:110:20)
at IncomingMessage.emit (events.js:207:7)
at endReadableNT (_stream_readable.js:1057:12)
at _combinedTickCallback (internal/process/next_tick.js:138:11)
at process._tickCallback (internal/process/next_tick.js:180:9)
[nodemon] app crashed - waiting for file changes before starting...
Any help is greatly appreciated, I've been tearing my hair out on this one for a while!
Thanks!

Node Is not reading collection

MongoError: failed to connect to server [localhost:27017] on first connect
at .<anonymous> (/Library/WebServer/Documents/nodeprojects/node_modules/mongodb-core/lib/topologies/server.js:313:35)
at emitOne (events.js:96:13)
at emit (events.js:188:7)
at .<anonymous> (/Library/WebServer/Documents/nodeprojects/node_modules/mongodb-core/lib/connection/pool.js:260:12)
at g (events.js:286:16)
at emitTwo (events.js:106:13)
at emit (events.js:191:7)
at Socket.<anonymous> (/Library/WebServer/Documents/nodeprojects/node_modules/mongodb-core/lib/connection/connection.js:162:49)
at Socket.g (events.js:286:16)
at emitOne (events.js:96:13)
at Socket.emit (events.js:188:7)
at connectErrorNT (net.js:1015:8)
at _combinedTickCallback (internal/process/next_tick.js:74:11)
at process._tickCallback (internal/process/next_tick.js:98:9)
name: 'MongoError',
message: 'failed to connect to server [localhost:27017] on first connect' }
/Library/WebServer/Documents/nodeprojects/node_modules/mongodb/lib/mongo_client.js:225
throw err
^
TypeError: Cannot read property 'collection' of null
at /Library/WebServer/Documents/nodeprojects/server.js:30:29
at connectCallback (/Library/WebServer/Documents/nodeprojects/node_modules/mongodb/lib/mongo_client.js:315:5)
at /Library/WebServer/Documents/nodeprojects/node_modules/mongodb/lib/mongo_client.js:222:11
at _combinedTickCallback (internal/process/next_tick.js:67:7)
at process._tickCallback (internal/process/next_tick.js:98:9)

Resources