import axios from 'axios';
import { Request, Response } from 'express';

interface ProxyRequest {
    body: string;
    headers: { [name: string]: string };
    method: string;
    url: string;
}

export function proxy(req: Request, res: Response) {
    const content = req.body as ProxyRequest;
    const request = {
        method: content.method,
        data: content.body,
        headers: content.headers,
        url: content.url
    };
    axios.request(request)
        .then(r => res.send(r.data))
        .catch(e => {
            if (e.response && e.response.status) {
                res.status(e.response.status).send(e.response.data);
            } else if (e.request) {
                res.status(400).send({
                    reason: 'PassThrough',
                    error: 'request error'
                });
            } else {
                res.status(400).send({
                    reason: 'PassThrough',
                    error: e.code
                });
            }
        });
}

import axios from 'axios';
import { Request, Response } from 'express';

interface ProxyRequest {
    body: string;
    headers: { [name: string]: string };
    method: string;
    url: string;
}

export function proxy(req: Request, res: Response) {
    const content = req.body as ProxyRequest;
    const request = {
        method: content.method,
        data: content.body,
        headers: content.headers,
        url: content.url
    };
    axios.request(request)
        .then(r => res.send(r.data))
        .catch(e => {
            if (e.response && e.response.status) {
                res.status(e.response.status).send(e.response);
            } else if (e.request) {
                res.status(400).send({
                    reason: 'PassThrough',
                    error: 'request error'
                });
            } else {
                res.status(400).send({
                    reason: 'PassThrough',
                    error: e.code
                });
            }
        });
}

--- 
+++ 
@@ -20,7 +20,7 @@
         .then(r => res.send(r.data))
         .catch(e => {
             if (e.response && e.response.status) {
-                res.status(e.response.status).send(e.response);
+                res.status(e.response.status).send(e.response.data);
             } else if (e.request) {
                 res.status(400).send({
                     reason: 'PassThrough',
Return data on error from the server
