Ohm-Management - Projektarbeit B-ME
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

catch_filter.js 1.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. "use strict";
  2. module.exports = function(NEXT_FILTER) {
  3. var util = require("./util");
  4. var getKeys = require("./es5").keys;
  5. var tryCatch = util.tryCatch;
  6. var errorObj = util.errorObj;
  7. function catchFilter(instances, cb, promise) {
  8. return function(e) {
  9. var boundTo = promise._boundValue();
  10. predicateLoop: for (var i = 0; i < instances.length; ++i) {
  11. var item = instances[i];
  12. if (item === Error ||
  13. (item != null && item.prototype instanceof Error)) {
  14. if (e instanceof item) {
  15. return tryCatch(cb).call(boundTo, e);
  16. }
  17. } else if (typeof item === "function") {
  18. var matchesPredicate = tryCatch(item).call(boundTo, e);
  19. if (matchesPredicate === errorObj) {
  20. return matchesPredicate;
  21. } else if (matchesPredicate) {
  22. return tryCatch(cb).call(boundTo, e);
  23. }
  24. } else if (util.isObject(e)) {
  25. var keys = getKeys(item);
  26. for (var j = 0; j < keys.length; ++j) {
  27. var key = keys[j];
  28. if (item[key] != e[key]) {
  29. continue predicateLoop;
  30. }
  31. }
  32. return tryCatch(cb).call(boundTo, e);
  33. }
  34. }
  35. return NEXT_FILTER;
  36. };
  37. }
  38. return catchFilter;
  39. };