2

I've never seen this before but I have an Express app running and on the localhost port Axios returns the request no problem but on the localhost domain it returns "bound consoleCall". Does anyone have any experience with this and know what it means?

<meta property="og:title" content="bound consoleCall" />

helpers.js

const axios = require('axios');
const {
  titleSuffix,
  organizationPath,
  varietyPath
} = require('./constants');

let organizationData = {};
let varietyData = {};

const Helpers = {
  fetchOrganization: (organizationID) => {
    return axios
      .get(organizationPath + organizationID)
      .then(response => {
        const organizationData = response.data.data;
        return organizationData
      })
      .catch(err => console.error);
  },

  setOrgSocialMeta: (growerHash, res) => {
    return Helpers.fetchOrganization(growerHash)
      .then(org => {
        return org.name + titleSuffix;
      });
  }
};

module.exports = Helpers;

server.js

const {
  setOrgSocialMeta,
  setVarSocialMeta
} = require('./helpers');

app.get(['/org/:growerHash/*', '/_org/:growerHash/*'], (req, res) => {
  setOrgSocialMeta(req.params.growerHash, res)
    .then(orgTitle => {
      res.locals.meta.title = orgTitle;
      res.locals.meta.og.title = orgTitle;
      res.render('org');
    });
});
nunya
  • 305
  • 1
  • 5
  • 17
  • Could you add code an comment exactly where you are seeing it? It may be related to this question: [In Node.js, on the console object, what is the context function?](https://stackoverflow.com/q/50572858/691711). – zero298 Jul 19 '18 at 16:01
  • Hey. I updated the post with the tag. – nunya Jul 19 '18 at 16:09
  • OK, this seems like a follow up from your other question: [How do you access Axios response with Express?](https://stackoverflow.com/q/51369468/691711). Could you add the relevant code that you updated to this question? I suspect that the issue may be with one of the return values from `fetchOrganization`. Please add that updated function as well as whatever function is now setting `es.locals.meta.og.title`. – zero298 Jul 19 '18 at 16:12
  • Sure. Updated code added. – nunya Jul 19 '18 at 16:16

1 Answers1

2

This means that Axios request failed but a failure wasn't properly handled; actual error is unknown because it was suppressed.

.catch(err => console.error) results in catching an error and resolving with console.error function, which is stringified to bound consoleCall.

It should be either

.catch(err => console.error(err))

or

.catch(console.error);

Or since a rejection isn't considered successful response, there should be no catch in fetchOrganization, but an error should be handled in route handler:

app.get(['/org/:growerHash/*', '/_org/:growerHash/*'], (req, res, next) => {
  setOrgSocialMeta(req.params.growerHash, res)
    .then(...)
    .catch(next); // passed to error-handling middleware
});
Estus Flask
  • 206,104
  • 70
  • 425
  • 565