JavaScript Split observable on error in RxJS

With promises, we can use a variant of .then to split up the chain when an error occurs. Here is an example using fetch

fetch('http://website.com').then(
  // Perform some logic
  (response) => response.json().then(({ answer }) => `Your answer: ${answer}`),
  // Skip json parsing when an error occurs
  (error) => 'An error occurred :(',
).then(console.log);

This allows me to skip the response processing logic and only respond to errors that were raised in the original fetch statement. Something similar in RxJS might look like this:

Observable.fromPromise(fetch('http://website.com'))
  // if I put .catch here, the result will be piped into flatMap and map
  .flatMap(response => response.json())
  .map(({ answer }) => `Your answer: ${answer}`)
  // if I put .catch here, errors thrown in flatMap and map will also be caught
  .subscribe(console.log);

As the comments in the code state, I can't simply put a catch operator in as it doesn't have the same behaviour as my promise chain.

I know I can get it with custom operators involving materialising, or merging an error catching observable with this one, but it all seems like pretty major overkill. Is there a simple way to achieve the promise chain behaviour?

Answer:1

How can I check if a div has a data-attribute and remove the div if it has that data-attribute, the opposite works like this: $("div[id='foo']").not('[data-type=edit]').remove();

How can I check if a div has a data-attribute and remove the div if it has that data-attribute, the opposite works like this: $("div[id='foo']").not('[data-type=edit]').remove();

  1. jquery check data attribute
  2. jquery check data attribute value
  3. jquery check data attribute exists
  4. jquery check data type
  5. jquery check data value
  6. jquery check data exists
  7. jquery check data in array
  8. jquery check data
  9. jquery check data empty
  10. jquery check data-toggle
  11. jquery check data attribute empty
  12. jquery check data attr
  13. jquery check data before submit
  14. jquery check data is null
  15. jquery check data length
  16. jquery check data-role
  17. jquery check data element
  18. jquery data check if exists
  19. jquery check if data attribute exists
  20. jquery check has data attribute

I have an issue with Chart.js. when I had my data inside Javascript, it showed the graph just fine. Now I would like to make it ready from JSON. but for some reason its reading wrong. I followed the ...

I have an issue with Chart.js. when I had my data inside Javascript, it showed the graph just fine. Now I would like to make it ready from JSON. but for some reason its reading wrong. I followed the ...

  1. chart wont show
  2. chart won't show up
  3. excel pie chart won't display
  4. excel chart won't display all data
  5. chart.js won't display
  6. excel won't display chart

I am trying to detect the given word is default keyword or not in JavaScript? Example: I have an array like arr=["function","some"] these are default keywords. If i write word like as 'function' or '...

I am trying to detect the given word is default keyword or not in JavaScript? Example: I have an array like arr=["function","some"] these are default keywords. If i write word like as 'function' or '...

I'm wondering how to access a public property from private and public functions in a JavaScript module? For example, if this is my module: var PersonModule = (function(){ var sayHello = ...

I'm wondering how to access a public property from private and public functions in a JavaScript module? For example, if this is my module: var PersonModule = (function(){ var sayHello = ...

  1. access public property in aspx page
  2. access public property
  3. access public property in javascript
  4. access public property c#
  5. access public property in another class c#
  6. public access property search
  7. public access property detail
  8. php access public property
  9. typescript access public property
  10. ms access public property
  11. access vba public property
  12. public access private property
  13. right to access public property
  14. how to access public property records for free
  15. multnomah public access property detail
  16. how to access public property records
  17. philadelphia public access property records
  18. c# cannot access public property
  19. asp.net access public property in master page
  20. honolulu public access property