node.js - StripeConnectionError - javascript

Recently receiving the following error when trying to look up either Stripe customers or accounts via Node.js.
I'm using stripe.accounts.retrieve and stripe.subscriptions.retrieve.
{
"type": "StripeConnectionError",
"stack": "Error: An error occurred with our connection to Stripe\n at Constructor._Error (/var/www/w3bbi/node_modules/stripe/lib/Error.js:12:17)\n at Constructor (/var/www/w3bbi/node_modules/stripe/lib/utils.js:124:13)\n at Constructor (/var/www/w3bbi/node_modules/stripe/lib/utils.js:124:13)\n at ClientRequest. (/var/www/w3bbi/node_modules/stripe/lib/StripeResource.js:206:9)\n at emitOne (events.js:96:13)\n at ClientRequest.emit (events.js:189:7)\n at TLSSocket.socketErrorListener (_http_client.js:358:9)\n at emitOne (events.js:96:13)\n at TLSSocket.emit (events.js:189:7)\n at emitErrorNT (net.js:1280:8)\n at _combinedTickCallback (internal/process/next_tick.js:74:11)\n at process._tickDomainCallback (internal/process/next_tick.js:122:9)",
"message": "An error occurred with our connection to Stripe",
"detail": {
"code": "ECONNRESET"
},
"raw": {
"message": "An error occurred with our connection to Stripe",
"detail": {
"code": "ECONNRESET"
}
}
}
Any idea on what may be causing this? I just upgraded my OpenSSL package on my Ubuntu server but that didn't seem to fix the issue.
This error doesn't seem to occur every time, but only every few attempts. Most times I successfully retrieve the Stripe subscription or account, but every so often, I get this error instead.
Also my node.js code is very simple--
stripe.subscriptions.retrieve(STRIPE_SUB_ID, function(err, subscription) {
//want to do something with subscription here, but i get err instead (only ever so often)
})
Thank you so much!!

Can you try curling the stripe API?
You can
Login into you stripe account
Go to https://stripe.com/docs/api/curl#retrieve_customer
Copy paste the request from sample. it will some thing like curl https://api.stripe.com/v1/customers/cus_DbAXqdmjzVPz2I \ -u
<your private api key>
Paste your response here
Let me know if it is working,
Also can you share your node js code (omitting your key) if it is ok.

Related

Cube.js Playground: Error while loading DB schema

I am currently learning Javascript/HTML/CSS in order to build some data dashboard.
I have found this tutorial https://d3-dashboard.cube.dev/setting-up-a-database-and-cube-js
Currently I am getting stuck at this part:
The next step is to create a Cube.js data schema.
When opening the Cube.js playground at: http://localhost:4000, I get the following output in my terminal:
🦅 Dev environment available at http://localhost:4000, I get the following error:
🚀 Cube.js server (0.21.1) is listening on 4000
Error: getaddrinfo ENOTFOUND <YOUR_DB_HOST_HERE>
at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:66:26)
And in the Cube.js playground webpage view:
Error while loading DB schema
Error: getaddrinfo ENOTFOUND <YOUR_DB_HOST_HERE> at
GetAddrInfoReqWrap.onlookup [as oncomplete](dns.js66:26)
I have edited the following file:
d3-dashboard/node_modules/#cubejs-backend/server-core/core/index.js
, with:
const checkEnvForPlaceholders = () => {
const placeholderSubstr = '<YOUR_DB_';
const credentials = [
'CUBEJS_API_SECRET=SECRET',
'CUBEJS_DB_TYPE=postgres',
'CUBEJS_DB_NAME=ecom',
'CUBEJS_WEB_SOCKETS=true'
/*'CUBEJS_DB_HOST',*/
/*'CUBEJS_DB_NAME',*/
/*'CUBEJS_DB_USER',*/
/*'CUBEJS_DB_PASS'*/
];
Any input on what I am doing wrong here?
I am totally new to apps and front-ends, so it might be something "stupid" that I am sking, but I really would like to learn from my mistakes :)
Thank you for your time and potential inputs/help!
Have a great day :)
You definitely should not edit any files in the node_modules directory. You should store the env variables in the .env file.
-your-cubejs-server-root
--schema
--.env
--//..
And it may look like
CUBEJS_DB_HOST=localhost
CUBEJS_DB_NAME=cubejs
CUBEJS_DB_USER=root
CUBEJS_DB_PASS=
CUBEJS_DB_TYPE=mysql
CUBEJS_API_SECRET=secret
The error you're getting is saying that the connection to the DB cannot be established. Because you're missing the proper CUBEJS_DB_HOST= variable.
The minimum required set of variables differs for each database and can be found here https://cube.dev/docs/connecting-to-the-database

handle request.js error in node application

I am using request to access data from an api. sometimes, when the api Url is down, node throws error and shuts down with the following error
at ClientRequest.emit (events.js:315:20)
at TLSSocket.socketErrorListener (_http_client.js:426:9)
at TLSSocket.emit (events.js:315:20)
at emitErrorNT (internal/streams/destroy.js:92:8)
at processTicksAndRejections (internal/process/task_queues.js:84:21)
errno: 'ENOTFOUND',
code: 'ENOTFOUND',
syscall: 'getaddrinfo',
hostname: APIURL
is there any way to handle this and prevent node from exiting?
my code is
const JSONdata= ()=>{
request({url:API_URL2,json:true},(error,response,body)=>{
const data=[]
var jsondata=body
data.push(jsondata)
const data2=JSON.stringify(data)
fs.writeFile('sample.txt',data2,(err) => { if(error){console.log(error} })})
You can use try/catch blocks that will keep your program running when certain functions error out. Here's a link describing how they work!
https://www.w3schools.com/js/js_errors.asp
Firstly request module has been deprecated request deprecated hence you can try some other packages like axios. Also while trying out api as well as database request try to have a try and catch block and in case of error try to have an appropriate error message displayed to the user.
try{
//your code
res.json("success")
}
catch(err){
res.json("Looks like something went wrong")
}

Catch error on IBM Watson IoT NodeJS client

I'm using the IBM Watson IoT NodeJS client to connect and use IBM Watson IoT.
This works when my object with credentials etc. is correct:
var client = new ibm_watson_iot.IotfGateway(MY-JSON-OBJECT-WITH-CREDENTIALS);
But if credentials is wrong, then I get:
events.js:160
throw er; // Unhandled 'error' event
^
Error: getaddrinfo ENOTFOUND 1234xyz.messaging.internetofthings.ibmcloud.com 1234xyz.messaging.internetofthings.ibmcloud.com:8883
at errnoException (dns.js:28:10)
at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:76:26)
error: Forever detected script exited with code: 1
How do I correctly catch this error in a nice way?
You can always use try/catch block to handler error like that
try{
var client = new ibm_watson_iot.IotfGateway(MY-JSON-OBJECT-WITH-CREDENTIALS);
}
catch(error) {
console.log("Error in connection.. Probably configuration object")
}

ADAL node js username password authentication

I am using the adal node js library 1.22, and trying to authenticate a user with username and password. I am getting a "unable to get local issuer certificate" error. The user is federated and the error happens on realm discovery.
var context = new AuthenticationContext(authorityUrl);
context.acquireTokenWithUsernamePassword(resource, sampleParameters.username, sampleParameters.password, sampleParameters.clientId, function(err, tokenResponse) {
if (err) {
console.log('well that didn\'t work: ' + err.stack);
} else {
console.log(tokenResponse);
}
});
The error stack:
Stack:
Error: unable to get local issuer certificate
at Error (native)
at TLSSocket.<anonymous> (_tls_wrap.js:1092:38)
at emitNone (events.js:86:13)
at TLSSocket.emit (events.js:185:7)
at TLSSocket._finishInit (_tls_wrap.js:610:8)
at TLSWrap.ssl.onhandshakedone (_tls_wrap.js:440:38)
{ Error: unable to get local issuer certificate
at Error (native)
at TLSSocket.<anonymous> (_tls_wrap.js:1092:38)
at emitNone (events.js:86:13)
at TLSSocket.emit (events.js:185:7)
at TLSSocket._finishInit (_tls_wrap.js:610:8)
at TLSWrap.ssl.onhandshakedone (_tls_wrap.js:440:38) code: 'UNABLE_TO_GET_ISSUER_CERT_LOCALLY' }
Wed, 14 Jun 2017 08:44:17 GMT:079c7b70-6ae1-461c-b433-cc3fe0c22783 - TokenRequest: VERBOSE: getTokenFunc returned with err
well that didn't work: Error: unable to get local issuer certificate
at Error (native)
at TLSSocket.<anonymous> (_tls_wrap.js:1092:38)
at emitNone (events.js:86:13)
at TLSSocket.emit (events.js:185:7)
at TLSSocket._finishInit (_tls_wrap.js:610:8)
at TLSWrap.ssl.onhandshakedone (_tls_wrap.js:440:38)
Can you please advise on what certificate i am missing and where to find it.
EDIT
after digging through the code i found that commenting out the global agent.ca part of the code resolved this issue and the library was able to perform a few steps after that, but it had a problem returning the token response from ADFS.
The log:
Wed, 14 Jun 2017 10:39:39 GMT:425e3117-a495-4f8e-8a12-e7e64dd0e37b - OAuth2Client: INFO: Get TokenServer returned this correlationId: 425e3117-a495-4f8e-8a12-e7e64dd0e37b
Wed, 14 Jun 2017 10:39:39 GMT:425e3117-a495-4f8e-8a12-e7e64dd0e37b - OAuth2Client: ERROR: Get Token request returned http error: 401 and server response: {"error":"invalid_client","error_description":"AADSTS70002: The request body must contain the following parameter: 'client_secret or client_assertion'.\r\nTrace ID: aadf1560-18ec-46f9-83b6-5932c2131200\r\nCorrelation ID: 425e3117-a495-4f8e-8a12-e7e64dd0e37b\r\nTimestamp: 2017-06-14 10:39:41Z","error_codes":[70002],"timestamp":"2017-06-14 10:39:41Z","trace_id":"aadf1560-18ec-46f9-83b6-5932c2131200","correlation_id":"425e3117-a495-4f8e-8a12-e7e64dd0e37b"}
Is there any configuration that i forgot,
if (!parametersFile) {
sampleParameters = {
tenant : 'tenant.onmicrosoft.com',
authorityHostUrl : 'https://login.microsoftonline.com',
clientId : 'aa461028-1fgf-46e5-ab9b-5adca324febc',
username : 'user#domain.net',
password : 'lamepassword'
};
}
var authorityUrl = sampleParameters.authorityHostUrl + '/' + sampleParameters.tenant;
var resource = '00000002-0000-0000-c000-000000000000';
The resource owner flow is strongly discouraged, and in some cases like federated users or users that require MFA, will just not work. This flow is the one in which your application handles the user's username and password directly and sends those in the request to the identity provider. This approach won't work if there are any extra interactions required as part of authentication such as requiring a second factor or dealing with federation. For these reasons and simple security principles (removing the need for the application to deal with the username and password) it's better to avoid this flow.
Since you are dealing with federated users, the resource owner won't work for you leaving you with the two preferred alternatives:
Use the authorization code flow if you want to authenticate as a user
Use the client credentials flow if you want to authenticate as an application.
See the "Web Application to Web API" scenario in the "Azure AD Authentication Scenarios" documentation for more information about choosing between these two options.

Using passport-steam with sails-generate-auth

I'm creating a SailsJS application, and I want users to log in only with Steam authentication. I used sails-generate-auth to create some boilerplate code with sails routes, but I'm having trouble plugging passport-steam into it.
https://github.com/kasperisager/sails-generate-auth
https://github.com/liamcurry/passport-steam
The reported error is:
C:\Users\Joe\testProject\node_modules\passport-steam\lib\passport-steam\strategy.js:67
id: result.response.players[0].steamid,
^
TypeError: Cannot read property 'steamid' of undefined
at steamapi.getPlayerSummaries.callback (C:\Users\Joe\testProject\node_modules\passport-steam\lib\passport-steam\strategy.js:67:43)
at IncomingMessage.<anonymous> (C:\Users\Joe\testProject\node_modules\passport-steam\node_modules\steam-web\lib\steam.js:218:7)
at IncomingMessage.emit (events.js:117:20)
at _stream_readable.js:944:16
at process._tickDomainCallback (node.js:486:13)
I have a feeling that this is caused by SteamWebAPI returning an empty response: {"response":{"players":[]}}, which is caused by a bogus SteamID in the request. The offending line is here in passport-steam: https://github.com/liamcurry/passport-steam/blob/master/lib/passport-steam/strategy.js#L53
Looking at identifier parameter to getUserProfile, it appears to be the entire Sails request scope. If I hardcode a good steam id into that array, I get this error:
C:\Users\Joe\testProject\api\services\passport.js:98
return next(new Error('Neither a username nor email was available'));
^
TypeError: undefined is not a function
at Authenticator.passport.connect (C:\Users\Joe\testProject\api\services\passport.js:98:12)
at module.exports (C:\Users\Joe\testProject\api\services\protocols\openid.js:24:12)
at steamapi.getPlayerSummaries.callback (C:\Users\Joe\testProject\node_modules\passport-steam\lib\passport-steam\strategy.js:72:11)
at IncomingMessage.<anonymous> (C:\Users\Joe\testProject\node_modules\passport-steam\node_modules\steam-web\lib\steam.js:218:7)
at IncomingMessage.emit (events.js:117:20)
at _stream_readable.js:944:16
at process._tickDomainCallback (node.js:486:13)
I think that makes sense since the steam response doesn't have a username nor email, but this is the profile: {"emails":[{}],"name":{}}
This is my passport configuration:
steam: {
name: 'Steam',
protocol: 'openid',
strategy: require('passport-steam').Strategy,
options: {
returnURL: 'http://localhost:1337/auth/steam/callback',
realm: 'http://localhost:1337/',
apiKey:'STEAM-API-KEY-REMOVED'
}
}
}
Not sure if there is something simple I'm missing, or I need to write a ton of custom handling. Is my configuration correct?
This is caused by out-of-date source code in npm. Even with the latest 0.1.4 version, the code is not correct. Replacing strategy.js in passport-steam with the latest version will fix this error.
Also, in api\services\passport.js, a little custom handling in passport.connect() needs to be added. The profile does not have a username, but has an id (user steamid) and displayName. These can be used to set the user model properties, e.g.
//steam auth
if (profile.hasOwnProperty('displayName')) {
user.username = profile.displayName;
}
Here is the ticket where the problem was solved: https://github.com/liamcurry/passport-steam/issues/10

Categories