Advertisement
Guest User

Untitled

a guest
Jul 21st, 2017
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. // An array, object or any data (eg. from an ajax call)
  2. let errorCodes = ['ErrorCode1', 'ErrorCode2', 'ErrorCode3', 'ErrorCode4', 'ErrorCodeBusiness']
  3.  
  4. let response = {
  5.  
  6. meta:
  7. {
  8. version: "1.0",
  9. time: "2017-07-20 08:28 AM GMT"
  10. },
  11.  
  12. errors:
  13. {
  14. errors:
  15. [
  16. {
  17. id: null,
  18. code: "ErrorCodeBusiness",
  19. message: "",
  20. uuid: ""
  21. }
  22. ],
  23. warnings: null
  24. }
  25.  
  26. };
  27.  
  28. //Find the error code that starts with given set of errors
  29. const hasError = _.find(response.errors.erorrs, (error) => {
  30. _.some(errorCodes, (code) => _.startsWith(code,error.code))
  31.  
  32. })
  33.  
  34. console.log(hasError);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement