Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const axios = require('axios')
- const convert = require('xml-js')
- const axiosRetry = require('axios-retry');
- const CLIENT = axios.create();
- CLIENT.defaults.timeout = 1000
- axiosRetry(CLIENT, {
- retryCondition: (error) => {
- return axiosRetry.isNetworkOrIdempotentRequestError(error) || error.code === 'ECONNABORTED';
- }
- });
- class Consult {
- constructor(username, password) {
- this.username = username
- this.password = password
- }
- async getResponse() {
- const config = {
- headers: {
- 'Content-Type': 'text/xml'
- }
- };
- const xml = 'string_conection'
- return await CLIENT.post('url', xml, config)
- .then(response => {
- const result = convert.xml2json(response.data, {
- compact: true,
- spaces: 4
- })
- return result
- })
- .catch(error => {
- console.log(error.code);
- });
- }
- }
- module.exports = Consult
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement