Commit a03e43d9 by Billy Larru

agregando interceptores de axios para formatear respuesta

parent 15601d1c
...@@ -361,14 +361,6 @@ const randomIntFromInterval = (minimum, maximum) => { ...@@ -361,14 +361,6 @@ const randomIntFromInterval = (minimum, maximum) => {
return Math.round(Math.random() * (maximum - minimum) + minimum); return Math.round(Math.random() * (maximum - minimum) + minimum);
} }
function formatResponse(resultAxios) {
return {
status: resultAxios.data.status || true,
message: resultAxios.data.message || `Operación exitosa`,
data: resultAxios.data.data || resultAxios.data
};
}
const cleanQueryParams = (params = {}) => { const cleanQueryParams = (params = {}) => {
for (var key in params) { for (var key in params) {
if (params.hasOwnProperty(key)) { if (params.hasOwnProperty(key)) {
...@@ -379,4 +371,22 @@ const cleanQueryParams = (params = {}) => { ...@@ -379,4 +371,22 @@ const cleanQueryParams = (params = {}) => {
} }
return params; return params;
} }
\ No newline at end of file
let interceptorsResponseAxios = () => {
axios.interceptors.response.use(function (response) {
// Do something with response data
let respuesta = {
status: response.data.status || true,
message: response.data.message || `Operación exitosa`,
data: response.data.data || response.data
};
console.log(respuesta)
return respuesta;
}, function (error) {
// Do something with response error
return Promise.reject(error);
});
}
interceptorsResponseAxios();
\ No newline at end of file
...@@ -29,6 +29,10 @@ ...@@ -29,6 +29,10 @@
<script type="text/javascript" src="../plantilla/assets/js/core/app.js"></script> <script type="text/javascript" src="../plantilla/assets/js/core/app.js"></script>
<!-- /core JS files --> <!-- /core JS files -->
<!--axios-->
<script src="../js/lib/axios.min.js" type="text/javascript"></script>
<!-- /Generales --> <!-- /Generales -->
<script src="../js/general.js" type="text/javascript"></script> <script src="../js/general.js" type="text/javascript"></script>
<script src="../js/pages/navbar.js" type="text/javascript"></script> <script src="../js/pages/navbar.js" type="text/javascript"></script>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment