restful.js icon indicating copy to clipboard operation
restful.js copied to clipboard

Cannot add functions to response body data object

Open christhomas opened this issue 9 years ago • 0 comments

I would like to transform the result returned from the REST api and put some accessor functions on the object in order to transform the data when its accessed.

However, when I do this, it crashes my browser and only when the functions are removed, then it works as normal.

instance.addResponseInterceptor((response:any,config:any) => {
    const { data, headers, statusCode } = response;

    return {
        data: RestClientData(data)
    }
});

function RestClientData(data:any){
    // this is a simple example, just to illustrate
    return {
        list: function() {
            return data._embedded.items
        }
    }
}

This will cause the browser to crash out, but removing the function, will return it to working state.

christhomas avatar Sep 02 '16 09:09 christhomas