@@ -91,17 +91,36 @@ module.exports = function (RED) {
9191 node.error(' Method is not specified.' , msg);
9292 errorFlag = true ;
9393 }
94-
94+ var setData = function (msg, data) {
95+ if (data) {
96+ if (data.response) {
97+ if (data.response.statusCode) {
98+ msg.statusCode = data.response.statusCode;
99+ }
100+ if (data.response.headers) {
101+ msg.headers = data.response.headers;
102+ }
103+ if (data.response.request && data.response.request.uri && data.response.request.uri.href) {
104+ msg.responseUrl = data.response.request.uri.href;
105+ }
106+ }
107+ if (data.body) {
108+ msg.payload = data.body;
109+ }
110+ }
111+ return msg;
112+ };
95113 if (!errorFlag) {
96114 node.status({ fill: ' blue' , shape: ' dot' , text: ' {{&className}}.status.requesting' } );
97- result.then(function (response) {
98- if (response.body !== null && response.body !== undefined) {
99- msg.payload = response.body;
100- }
101- node.send(msg);
115+ result.then(function (data) {
116+ node.send(setData(msg, data));
102117 node.status({} );
103118 }).catch(function (error) {
104- node.error(error, msg);
119+ var message = null;
120+ if (error && error.body && error.body.message) {
121+ message = error.body.message;
122+ }
123+ node.error(message, setData(msg, error));
105124 node.status({ fill: ' red' , shape: ' ring' , text: ' node-red:common.status.error' } );
106125 });
107126 }
0 commit comments