Advertisement
Guest User

Untitled

a guest
Feb 25th, 2019
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. const axios = require('axios')
  2. const convert = require('xml-js')
  3. const axiosRetry = require('axios-retry');
  4.  
  5.  
  6. const CLIENT = axios.create();
  7. CLIENT.defaults.timeout = 1000
  8. axiosRetry(CLIENT, {
  9. retryCondition: (error) => {
  10. return axiosRetry.isNetworkOrIdempotentRequestError(error) || error.code === 'ECONNABORTED';
  11. }
  12. });
  13.  
  14. class Consult {
  15. constructor(username, password) {
  16. this.username = username
  17. this.password = password
  18. }
  19.  
  20. async getResponse() {
  21. const config = {
  22. headers: {
  23. 'Content-Type': 'text/xml'
  24. }
  25. };
  26. const xml = 'string_conection'
  27.  
  28. return await CLIENT.post('url', xml, config)
  29. .then(response => {
  30. const result = convert.xml2json(response.data, {
  31. compact: true,
  32. spaces: 4
  33. })
  34. return result
  35. })
  36. .catch(error => {
  37. console.log(error.code);
  38. });
  39. }
  40. }
  41.  
  42. module.exports = Consult
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement