javascript - Rest request - Getting the needed value in catch -


i use following request, , works problem since data coming redirect call (http- 302) retrieved in catch statment dont like... there better way achieve ?

const request = require('request-promise-native');  request({             uri: api + '/oauth/',             method: 'get',             qs: {                 client_id: 'proxy',                 grant_type: 'authorization_code',                 response_type: 'code'             },             headers: {                 'authorization': 'bearer ' + token             },             followredirect: false         }).then(function (data) {             console.log('not needed data...');         }).catch(function (err) {    //here im getting required data          if (err.statuscode === 302) {           //here i'm parsing err obj required data          //which need except im getting in catch block...           console.log('code is:  ' + data.query.code)              }         }) 

edit:

i've changed code , got error data undefined

request({             uri: api + '/oauth/',             method: 'get',             simple:false,             qs: {                 client_id: 'proxy',                 grant_type: 'authorization_code',                 response_type: 'code'             },             headers: {                 'authorization': 'bearer ' + token             },             followredirect: false         }).then(function (data) {             console.log('not needed data...');         }).catch(function (err) {    //here im getting required data          if (err.statuscode === 302) {           //here i'm parsing err obj required data          //which need except im getting in catch block...           console.log('code is:  ' + data.query.code)              }         }) 


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -