Guest User

Untitled

a guest
Feb 22nd, 2018
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. tak jest źle!:
  2.  
  3. ```
  4. function costam () {
  5. return new Promise((resolve, reject) => {
  6. reject(new Error('Abrakadabra hokus pokus!'))
  7. })
  8. }
  9. function costamRobiaceCostam () {
  10. return costam().then(() => {
  11. }).catch(err => err)
  12. }
  13. async function abecadlo () {
  14. try {
  15. await costamRobiaceCostam()
  16. }
  17. catch (err) {
  18. console.log('wysypao sie')
  19. }
  20. }
  21. abecadlo()
  22. ```
  23.  
  24. a tak być powinno:
  25.  
  26. ```
  27. function costam () {
  28. return new Promise((resolve, reject) => {
  29. reject(new Error('Abrakadabra hokus pokus!'))
  30. })
  31. }
  32. function costamRobiaceCostam () {
  33. return costam().then(() => {
  34. })
  35. // jeśli nic z errorem nie zamierzamy zrobić, kasujemy poniższą linijkę
  36. .catch(err => {throw err})
  37. }
  38. async function abecadlo () {
  39. try {
  40. await costamRobiaceCostam()
  41. }
  42. catch (err) {
  43. console.log('wysypao sie')
  44. }
  45. }
  46. abecadlo()
  47. ```
Add Comment
Please, Sign In to add comment