Add missing rejection handling for Promises (#7008)
* Add eslint-plugin-promise to detect uncaught rejections * Move alert generation for errors to actions/alert * Add missing rejection handling for Promises * Use catch() instead of onReject on then() Then it will catches rejection from onFulfilled. This detection can be disabled by `allowThen` option, though.
This commit is contained in:
		
					parent
					
						
							
								e7a1716701
							
						
					
				
			
			
				commit
				
					
						2c51bc0ca5
					
				
			
		
					 13 changed files with 84 additions and 44 deletions
				
			
		|  | @ -9,6 +9,12 @@ const limit = 1024; | |||
| // https://webkit.org/status/#specification-service-workers
 | ||||
| const asyncCache = window.caches ? caches.open('mastodon-system') : Promise.reject(); | ||||
| 
 | ||||
| function printErrorIfAvailable(error) { | ||||
|   if (error) { | ||||
|     console.warn(error); | ||||
|   } | ||||
| } | ||||
| 
 | ||||
| function put(name, objects, onupdate, oncreate) { | ||||
|   return asyncDB.then(db => new Promise((resolve, reject) => { | ||||
|     const putTransaction = db.transaction(name, 'readwrite'); | ||||
|  | @ -77,7 +83,9 @@ function evictAccountsByRecords(records) { | |||
| 
 | ||||
|     function evict(toEvict) { | ||||
|       toEvict.forEach(record => { | ||||
|         asyncCache.then(cache => accountAssetKeys.forEach(key => cache.delete(records[key]))); | ||||
|         asyncCache | ||||
|           .then(cache => accountAssetKeys.forEach(key => cache.delete(records[key]))) | ||||
|           .catch(printErrorIfAvailable); | ||||
| 
 | ||||
|         accountsMovedIndex.getAll(record.id).onsuccess = ({ target }) => evict(target.result); | ||||
| 
 | ||||
|  | @ -90,11 +98,11 @@ function evictAccountsByRecords(records) { | |||
|     } | ||||
| 
 | ||||
|     evict(records); | ||||
|   }); | ||||
|   }).catch(printErrorIfAvailable); | ||||
| } | ||||
| 
 | ||||
| export function evictStatus(id) { | ||||
|   return evictStatuses([id]); | ||||
|   evictStatuses([id]); | ||||
| } | ||||
| 
 | ||||
| export function evictStatuses(ids) { | ||||
|  | @ -110,7 +118,7 @@ export function evictStatuses(ids) { | |||
|       idIndex.getKey(id).onsuccess = | ||||
|         ({ target }) => target.result && store.delete(target.result); | ||||
|     }); | ||||
|   }); | ||||
|   }).catch(printErrorIfAvailable); | ||||
| } | ||||
| 
 | ||||
| function evictStatusesByRecords(records) { | ||||
|  | @ -127,7 +135,9 @@ export function putAccounts(records) { | |||
|         const oldURL = target.result[key]; | ||||
| 
 | ||||
|         if (newURL !== oldURL) { | ||||
|           asyncCache.then(cache => cache.delete(oldURL)); | ||||
|           asyncCache | ||||
|             .then(cache => cache.delete(oldURL)) | ||||
|             .catch(printErrorIfAvailable); | ||||
|         } | ||||
|       }); | ||||
| 
 | ||||
|  | @ -145,10 +155,14 @@ export function putAccounts(records) { | |||
|     oncomplete(); | ||||
|   }).then(records => { | ||||
|     evictAccountsByRecords(records); | ||||
|     asyncCache.then(cache => cache.addAll(newURLs)); | ||||
|   }); | ||||
|     asyncCache | ||||
|       .then(cache => cache.addAll(newURLs)) | ||||
|       .catch(printErrorIfAvailable); | ||||
|   }).catch(printErrorIfAvailable); | ||||
| } | ||||
| 
 | ||||
| export function putStatuses(records) { | ||||
|   put('statuses', records).then(evictStatusesByRecords); | ||||
|   put('statuses', records) | ||||
|     .then(evictStatusesByRecords) | ||||
|     .catch(printErrorIfAvailable); | ||||
| } | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue