@@ -22,7 +22,6 @@ module.exports = function(RED) {
2222 msg . payload = `Either username or password should not empty to make ${ node . type } node working properly.` ;
2323 node . send ( msg ) ;
2424 } else {
25- msg . method = "get" ;
2625 httpRequestCall ( msg , function ( err , data ) {
2726 if ( err ) {
2827 node . send ( err ) ;
@@ -46,7 +45,13 @@ module.exports = function(RED) {
4645 timeout : 30000 , //if the response not comes in 30sec axios will abort the request;
4746 url : msg . dbUrl , // cloudant database url for views, query's
4847 method : msg . method //method used to communicate with cloudant database i.e get,post,put,delete,patch
49- } ;
48+ } ;
49+
50+ if ( msg . method . toUpperCase ( ) == "GET" ) {
51+ config . params = msg . payload || { } ;
52+ } else {
53+ config . data = { "docs" : msg . payload } ;
54+ }
5055
5156 axios
5257 . request ( config )
@@ -55,7 +60,24 @@ module.exports = function(RED) {
5560 msg . payload = response . data ;
5661 callback ( null , msg ) ;
5762 } ) . catch ( function ( exception ) {
58- msg . payload = exception ;
63+ if ( exception . response ) {
64+ // The request was made and the server responded with a status code
65+ // that falls out of the range of 2xx
66+ console . log ( exception . response . data ) ;
67+ console . log ( exception . response . status ) ;
68+ console . log ( exception . response . headers ) ;
69+ msg . payload = exception . response ;
70+ } else if ( exception . request ) {
71+ // The request was made but no response was received
72+ // `error.request` is an instance of XMLHttpRequest in the browser and an instance of
73+ // http.ClientRequest in node.js
74+ console . log ( exception . request ) ;
75+ msg . payload = exception . request ;
76+ } else {
77+ // Something happened in setting up the request that triggered an Error
78+ console . log ( 'Error' , exception . message ) ;
79+ msg . payload = exception . message ;
80+ }
5981 callback ( null , msg ) ;
6082 } ) ;
6183 }
0 commit comments