Advertisement
Guest User

Untitled

a guest
Jun 30th, 2015
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.35 KB | None | 0 0
  1. function guaranteedPost(endpointId, wallPost, attempts){
  2. var attempts = attempts || 0
  3. return graph.postAsync(endpointId + '/feed', wallPost)
  4. .then(function(response){
  5. return response
  6. })
  7. .catch(function(error){
  8. if(error.message != errorMessage){
  9. return Promise.reject(error.message)
  10. }
  11. console.log('Retry attempt #: ' + attempts)
  12. if(attempts == 5){
  13. return Promise.reject('Too many errors')
  14. }
  15. // console.log(error)
  16. return Promise.delay(5000).then(function(){
  17. return guaranteedPost(endpointId, wallPost, attempts + 1)
  18. })
  19. });
  20. }
  21.  
  22. function guaranteedPost(endpointId, wallPost, attempts){
  23. var attempts = attempts || 0
  24. return graph.postAsync(endpointId + '/feed', wallPost)
  25. .then(function(response){
  26. return response
  27. })
  28. .catch(function(error){
  29. if(error.message != errorMessage){
  30. return Promise.reject(error.message)
  31. }
  32. console.log('Retry attempt #: ' + attempts)
  33. else if(attempts == 5){ //BLOWS UP
  34. return Promise.reject('Too many errors')
  35. }
  36. // console.log(error)
  37. return Promise.delay(5000).then(function(){
  38. return guaranteedPost(endpointId, wallPost, attempts + 1)
  39. })
  40. });
  41. }
  42.  
  43. else if(attempts == 5){
  44. ^^^^
  45. SyntaxError: Unexpected token else
  46.  
  47. console.log('Retry attempt #: ' + attempts)
  48.  
  49. console.log('Retry attempt #: ' + attempts)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement