t3chnoboy / amazon-product-api

:credit_card: Amazon Product Advertising API client
366 stars 104 forks source link

Handle the error condition when internet connection is down #13

Closed henrikekblad closed 9 years ago

henrikekblad commented 9 years ago

Hmm. CI fails...

t3chnoboy commented 9 years ago

nvm, PR checker is broken :grin: Only works on master for some reason :confused: I'll test it locally.

henrikekblad commented 9 years ago

Weird.. I see now that I seem to get two callbacks.


err: { [Error: getaddrinfo ENOTFOUND webservices.amazon.co.uk] code: 'ENOTFOUND', errno: 'ENOTFOUND', syscall: 'getaddrinfo', hostname: 'webservices.amazon.co.uk' } res: undefined


err: No response (check internet connection) res: undefined


henrikekblad commented 9 years ago

Just a sec.. I think I've found it.

henrikekblad commented 9 years ago

Ok, seeing the correct behaviour here now. Sorry for the push flooding.

t3chnoboy commented 9 years ago

cool can you squash the commits and push --force?

henrikekblad commented 9 years ago

Hmm. never done that before. Do you have some nifty command line tricks?

t3chnoboy commented 9 years ago

sure :smile: Run git rebase -i HEAD~3 and read the instructions.

t3chnoboy commented 9 years ago

Let me know if you face any difficulties.

henrikekblad commented 9 years ago

Ok, done (I hope).

t3chnoboy commented 9 years ago

Yeah! Looks good :+1:

t3chnoboy commented 9 years ago

Thank you for your contribution!

t3chnoboy commented 9 years ago

I'll ship it to npm as 2.2.3 in a few minutes.

Krupen commented 7 years ago

Hi, I am also getting the same error when trying to use it in Firebase-cloud-functions, below is my code:

var express = require('express');
var fs = require('fs');
var amazon = require('amazon-product-api');
var _ = require('lodash');
var request = require('request');

var functions = require('firebase-functions');
const admin = require('firebase-admin');

// CORS Express middleware to enable CORS Requests.
const cors = require('cors')({
    origin: true
});
admin.initializeApp(functions.config().firebase);

//allattentionhere@gmail.com
var client = amazon.createClient({
    awsId: "aws ID",
    awsSecret: "aws Secret",
    awsTag: "aws Tag"
});

//https://us-central1-pricestalker-ba4cb.cloudfunctions.net/amazonsearch?asin=asincode
exports.amazonsearch = functions.https.onRequest((req, res) => {

    if (req.method === 'PUT') {
        res.status(403).send('Forbidden!');
    }
    cors(req, res, () => {
        const asin = req.query.asin;
        if (!asin) {
            asin = req.body.asin;
        }

        client.itemLookup({
            idType: 'ASIN',
            itemId: asin,
            responseGroup: 'ItemAttributes,Offers,Images',
            domain: 'webservices.amazon.in'
        }, function(err, results, response) {

            if (err) {
                res.status(404).send(`asin: ${asin}  ` + `| response:  ` + JSON.stringify(response) + JSON.stringify(err));
            } else {
            console.log(JSON.stringify(results));
            }
        });

    });
});

To test, just visit url: https://us-central1-pricestalker-ba4cb.cloudfunctions.net/amazonsearch?asin=asincode

Response is:

asin: BO11 | response: undefined{"code":"ENOTFOUND","errno":"ENOTFOUND","syscall":"getaddrinfo","hostname":"webservices.amazon.in","host":"webservices.amazon.in","port":443}
Krupen commented 7 years ago

Solved, Firebase does not allow outbound network calls in free tier.