-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: add cacheError decorator to catch cache error (#9)
- Loading branch information
1 parent
0b3ee2f
commit 9bb93f3
Showing
2 changed files
with
26 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/** | ||
* Loose the cache dependency by wrapping the cache errors, if cache malfunction, the application will still work. | ||
* | ||
* @returns {Promise<any>} | ||
*/ | ||
export const WrapCacheErrors = () => { | ||
return (_target: any, _propertyKey: string, descriptor: PropertyDescriptor) => { | ||
const originalMethod = descriptor.value; | ||
|
||
descriptor.value = async function (...args: any[]) { | ||
try { | ||
const result = await originalMethod.apply(this, args); | ||
return result; | ||
} catch (err) { | ||
console.error('Cache Error: ', err.message); | ||
return null; | ||
} | ||
}; | ||
|
||
return descriptor; | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters