Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2021
19
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1.  
  2. class Screen {
  3. constructor() {
  4. console.log('Created screen');
  5. }
  6.  
  7. process() {
  8. this.getReports()
  9. .then(data => {
  10. this.renderReports(data);
  11. })
  12. .catch(err => console.error(`Something went wrong ${err.message}`));
  13. }
  14.  
  15. getReports = async function () {
  16. try {
  17. const res = await fetch('http://192.168.0.95:8080/api/reports/', {
  18. headers: {
  19. 'Content-Type': 'application/json',
  20. //Authorization: `Token ${testToken}`,
  21. },
  22. });
  23.  
  24. if (!res.ok) throw new Error(`Something went wrong.. ${res.status}`);
  25.  
  26. return res.json();
  27. } catch (err) {
  28. throw err;
  29. }
  30. };
  31.  
  32. renderReports(reports) {
  33. console.log(reports);
  34. }
  35. }
  36.  
  37. const newScreen = new Screen();
  38.  
  39. btn.addEventListener('click', function () {
  40. newScreen.process();
  41. });
  42.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement