Last active
October 18, 2022 06:55
-
-
Save tuanna-hsp/fa2ce03f362e4f505cf3da010c0e8346 to your computer and use it in GitHub Desktop.
Type of clients
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
class ScrapingClient extends AbstractAggregationClient { | |
// | |
// Extending life cycle hooks | |
// | |
protected beforeAggregation(params): void { | |
// Calling superclass implementation to do some common preparation | |
super.beforeAggregation(params); | |
// Initialize Chrome instance for scraping | |
// Initialize file system for storing debug data | |
} | |
protected afterAggregation(params): void { | |
// Upload debug data to AWS S3 | |
// Remove debug data from file system | |
// Cleanup Chrome instance | |
// Calling superclass implementation to do some common cleanup | |
super.afterAggregation(params); | |
} | |
protected onError(params, error): AggregationResult { | |
// Default error handling for scraping clients | |
if (error.message === "Timeout") { | |
return new AggregationResult(ResultCode.SCRAPING_TIMEOUT); | |
} | |
// Fallback to the superclass implementation for other type of errors | |
return super.onError(params, error); | |
} | |
// | |
// Other utility methods for scraping | |
// | |
} | |
class ApiClient extends AbstractAggregationClient { | |
// | |
// Extending life cycle hooks | |
// | |
protected onError(params, error): AggregationResult { | |
// Default error handling for API clients. Handling common API status codes | |
if (error.response.statusCode === 500) { | |
return new AggregationResult(ResultCode.ERROR_FROM_SAAS); | |
} | |
if (error.response.statusCode === 401) { | |
return new AggregationResult(ResultCode.INCORRECT_CREDENTIALS_GIVEN); | |
} | |
// Fallback to the superclass implementation for other type of errors | |
return super.onError(params, error); | |
} | |
// | |
// Other utility methods for calling SaaS APIs | |
// | |
} | |
class GitHubClient extends ApiClient { | |
protected getAccountsImpl(): AggregationResult { | |
// GitHub getAccounts logic | |
} | |
protected onError(params, error): AggregationResult { | |
// Handle GitHub specific errors | |
// Fallback to the superclass implementation for common errors | |
return super.onError(params, error); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment