0
  • I am doing a node proxy for my api calls.
  • in node server I am successfully able to hit the api and get the response.
  • where in client side when I dont hard the url I am getting the below Error filePresentData response----> Promise {<pending>}
  • where as when I hard code I am getting the below error. filePresentData error----> Error: Network Error at createError (createError.js:16) at XMLHttpRequest.handleError (xhr.js:87)
  • I debugged by putting consoles.
  • but still not sucessful.
  • providing my logs, server and client side code below.
  • can you tell me how to fix it.

action.js

export function filePresentData() {

console.log(" filePresentData----> ");

var jumpSearch = 'gr';
var searchVal = jumpSearch;
var searchMode = 'smart';

//we are using this replace method to hack the name search Mode
jumpSearch = jumpSearch.replace('/', '%2F');
jumpSearch = jumpSearch.replace('#', '%23');
jumpSearch = jumpSearch.replace('+', '%2B');
jumpSearch = jumpSearch.replace('.', '%2E');
jumpSearch = jumpSearch.replace(/'|-/g, "");
jumpSearch = jumpSearch.replace(/ /g, "%20");

let environment = globalConfig.getConfig('environment');
searchVal = searchVal.replace(/'|-/g, "");

var url = `/hjhjhj/swim/${searchMode}/${jumpSearch}`;
console.log(" fetchjumpData Url---> ", url);
if (environment !== "local") {
    url = `/hjhjhj/swim/${searchMode}/${searchVal}`;
    console.log(" inside if fetchjumpData Url---> ", url);
}
console.log(" Url----> ", url, searchMode, searchVal, jumpSearch);

return (dispatch) => {
    var response;
    response = axios.get(url);

    //response = axios.get('http://world.com/jkjk/dffddfkldfkldlf/?id=rwekleklerklklerklerk');
    console.log(" filePresentData response----> ", response);

    response.then((result) => {
        console.log(" filePresentData result----> ", result);

        if (result) {
            dispatch(fetchDataSuccess(result));
        }
    }).catch((error) => {
        console.log(" filePresentData error----> ", error);

        dispatch(setSearchError(error));
    });
};

}

error for scenario 1

filePresentData----> 
SearchBoxAction.js:214  fetchjumpData Url--->  /hjhjhj/swim/smart/gr
SearchBoxAction.js:217  inside if fetchjumpData Url--->  /hjhjhj/swim/smart/gr
SearchBoxAction.js:219  Url---->  /hjhjhj/swim/smart/gr smart gr gr
SearchBoxAction.js:226  filePresentData response---->  Promise {<pending>}
SearchBoxAction.js:235  filePresentData error---->  Error: Network Error
    at createError (createError.js:16)
    at XMLHttpRequest.handleError (xhr.js:87)



Request URL: http://world.com/jkjk/dffddfkldfkldlf/?id=rwekleklerklklerklerk
Request Method: GET
Status Code: 401 Unauthorized

error for scenario 2

 filePresentData----> 
SearchBoxAction.js:214  fetchjumpData Url--->  /hjhjhj/swim/smart/gr
SearchBoxAction.js:217  inside if fetchjumpData Url--->  /hjhjhj/swim/smart/gr
SearchBoxAction.js:219  Url---->  /hjhjhj/swim/smart/gr smart gr gr
SearchBoxAction.js:226  filePresentData response---->  Promise {<pending>}

filePresentData result----> {data: {…}, status: 200, statusText: "OK", headers: {…}, config: {…}, …} SearchBoxAction.js:235 filePresentData error----> TypeError: networksData.slice is not a function

server file

const express = require('express');
const axios = require('axios');
const mime = require('mime-types');

const router = express.Router();
const ResponseUtil = require('../../utils/ResponseUtil');
const AppConstants = require('../../../constants/AppConstants');

const credentials = require('../../../internals/credentials.json');

const memberGroupingHelper = require('../../helpers/pcp/memberGrouping');
const exportHelper = require('../../helpers/pcp/pcpExportHelper');
const formatExportData = require('../../helpers/pcp/formatExportData');

const pcpCommonHelper = require('../../helpers/pcp/pcpCommonHelper');
const pcpProvDataHelper = require('../../helpers/group/getProvData');

//const aggregateHelper = require('../../helpers/group/aggregateFilter');

const {
    PcpAggregatejumpsApi
} = require('psv-svc-utils');


router.get('/:searchMode/:jumpSearch', (req, res, next) => {
    //  router.get('/ecmstest', (req, res, next) => {


    const {
        originalUrl
    } = req;

    //console.log(" originalUrl  ", originalUrl);

    const mode = req.params.searchMode;

    const value = encodeURIComponent(req.params.jumpSearch);

    // const url = `/wewewe/weiopewopewopop/jumps?mode=${mode}&value=${value}`;

    console.log("document 40--->", mode);
    console.log("for document Testing0--->", mode);

    // const url = `http://world.com/jkjk/dffddfkldfkldlf/?id=rwekleklerklklerklerk`;
    const url = `/tes/weiopewopewopop/ecmsdocuments/?id=rwekleklerklklerklerk`;
    console.log("AppConstants.GET_JWT_TOKEN_URL--->", AppConstants.GET_JWT_TOKEN_URL);

    var formatUrl = AppConstants.wewewewewe_CONTENT_CENTRAL + url;


    axios.get(AppConstants.GET_JWT_TOKEN_URL, {
            auth: {
                username: credentials.auth.racfId,
                password: credentials.auth.password
            }
        })
        .then((jwtResponse) => {
            console.log("jwt then----->", jwtResponse.data.jwt);

            console.log('then formatUrl --->', formatUrl);



            // Return the promise from get so it is applied to the promise chain
            return axios.get(formatUrl, {
                    headers: {
                        "Authorization": `Bearer ${jwtResponse.data.jwt}`,
                        "Content-Type": 'application/json'

                    }
                })

                .then((response) => {
                    // try {
                    console.log("document suceess then0--->");
                    const file = Buffer.from(response.data.content, 'base64');
                    const fileType = mime.contentType(response.data.contentInfo.fileType);
                    const fileExtension = response.data.contentInfo.fileType.toLowerCase();
                    const fileName = `filename=${response.data.contentInfo.id}.${fileExtension}`;
                    console.log("document suceess fileName--->", fileName);




                    return ResponseUtil.callService(res, url);

                })

                .catch((e) => {
                    // Catch any error that occurred in the promise chain...
                    if (e.response) {
                        return res.status(e.response.status).send(e.response.data);
                    }
                    return res.status(500).send(e.message || 'Something wrong');
                });




        });


    // ResponseUtil.callService(res, url);



});

module.exports = router;

server logs

controllers---> [ 'C:/codebase/fddfdf/server/controllers/root.js' ]
server is listening on 1010
  callService ===>  /hjhjhj/swim/i8cx/userimages
  URL ===>  http://veg/hjhjhj//i8cx/userimages
searchMode value---> gr
searchMode 3---> Smart
for document Testing---> Smart
  callService ===>  /hjhjhj/swim?mode=Smart&value=gr
  URL ===>  http://veg/hjhjhj/?mode=Smart&value=gr
  callService ===>  /hjhjhj/swim/=-wewewewe/erjkerjkerjkjker?history=false
  URL ===>  http://veg/hjhjhj//=-wewewewe/erjkerjkerjkjker?history=false
  callService ===>  /hjhjhj/swim/edfdfdf/erjkerjkerjkjker?history=false
  URL ===>  http://veg/hjhjhj//edfdfdf/erjkerjkerjkjker?history=false
  callService ===>  /hjhjhj/swim/wewewewe/erjkerjkerjkjker?history=false
  URL ===>  http://veg/hjhjhj//wewewewe/erjkerjkerjkjker?history=false
  callService ===>  /hjhjhj/swim/dew/erjkerjkerjkjker?history=false
  URL ===>  http://veg/hjhjhj//dew/erjkerjkerjkjker?history=false
  callService ===>  /hjhjhj/swim/wewewewe/erjkerjkerjkjker?history=false
  URL ===>  http://veg/hjhjhj//wewewewe/erjkerjkerjkjker?history=false
document 40---> smart
for document Testing0---> smart
AppConstants.GET_JWT_TOKEN_URL---> https://ererll;l;/erklklk
then formatUrl ---> http://world.com/jkjk/dffddfkldfkldlf/?id=rwekleklerklklerklerk
document suceess then0--->
document suceess fileName---> filename=a2c93187-5422-46c7-bcf7-e663c28dcd2e.pdf
  callService ===>  /jkjk/dffddfkldfkldlf/?id=rwekleklerklklerklerk
  else if responseutil.jsURL ===>  http://world.com/jkjk/dffddfkldfkldlf/?id=rwekleklerklklerklerk
  URL ===>  http://world.com/jkjk/dffddfkldfkldlf/?id=rwekleklerklklerklerk
  callService ===>  /hjhjhj/swim/i8cx/userimages
  URL ===>  http://veg/hjhjhj//i8cx/userimages
  • 1
    "*`filePresentData response----> Promise {}`*" is not an error, that's simply the representation of a promise that has not yet settled. – Bergi Jun 11 '19 at 14:58
  • 1
    Can you post the serverside logs as well, please? – Bergi Jun 11 '19 at 14:58
  • @Bergi hey updated the server logs, can you let me know how to make it settled –  Jun 11 '19 at 15:06
  • Keep in mind that if you log the promise, it will be shown as "pending" (as the top-level console log is not reactive). But if you expand it, you might find the resolved value. – Seblor Jun 11 '19 at 15:07
  • @Bergi hey if I opne the promise it shows promiseValue as undefined `Promise {} __proto__: Promise [[PromiseStatus]]: "pending" [[PromiseValue]]: undefined` –  Jun 11 '19 at 15:09
  • 1
    @zizi There is nothing wrong with a pending promise. You should get either `filePresentData result` or `filePresentData error`, and that's all what matters. (If the promise stays pending forever, something is wrong with your server, e.g. it's never sending any response). – Bergi Jun 11 '19 at 15:36
  • 1
    @zizi Those logs from the server don't seem to match your code. I don't see any `document 40--->` in there. But regardless of possible renamings, does your server work as expected or not? Check with the browser devtools, or even some other tool like postman, whether the response is the one you expect. If it is not, ignore the client code and fix your server first. If it is, then the server code is irrelevant and we need to concentrate on your client code only. – Bergi Jun 11 '19 at 15:38
  • @Bergi hey saw the browser console...I am seeing this stuff in my console `filePresentData result----> {data: {…}, status: 200, statusText: "OK", headers: {…}, config: {…}, …} SearchBoxAction.js:235 filePresentData error----> TypeError: networksData.slice is not a function` –  Jun 11 '19 at 15:41
  • You need to resolve the promise `axios.get().then((response) => {})` – doublesharp Jun 11 '19 at 15:43
  • @Bergi hey sorry updated server console again...checked in postman I am getting the response –  Jun 11 '19 at 15:43
  • 1
    @zizi Then apparently there is a problem in `dispatch(fetchDataSuccess(result));` . Did you check line 235 of `SearchBoxAction.js`, and why `networksData` doesn't have the expected value there? – Bergi Jun 11 '19 at 15:44
  • @Bergi hey it worked..can you help me with this one too https://stackoverflow.com/questions/56385656/react-app-local-storage-is-not-setting-up/56467574#56467574 –  Jun 11 '19 at 18:32
  • @Bergi hey can you help me with this one too https://stackoverflow.com/questions/56549588/content-key-is-not-throwing-values-inside-data –  Jun 11 '19 at 20:07

0 Answers0