generated from MapColonies/ts-server-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 0
feat: added validation against the extractable service (MAPCO-9560, MAPCO-9561) #51
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
7afd7ba
feat: added validation against the extractable service
lirantul123 a2e642a
fix: finish updateStatus and asaf changes
lirantul123 ce57f3a
chore: meanningful name
lirantul123 19633a0
chore: asaf comments
lirantul123 82655a1
refactor: asaf changes
lirantul123 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
61 changes: 61 additions & 0 deletions
61
src/externalServices/extractable-management/extractableCall.ts
This file contains hidden or 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,61 @@ | ||
| import axios from 'axios'; | ||
| import { inject, injectable } from 'tsyringe'; | ||
| import { Logger } from '@map-colonies/js-logger'; | ||
| import { StatusCodes } from 'http-status-codes'; | ||
| import { Tracer } from '@opentelemetry/api'; | ||
| import { withSpanAsyncV4 } from '@map-colonies/telemetry'; | ||
| import { SERVICES } from '../../common/constants'; | ||
| import { AppError } from '../../common/appError'; | ||
| import { IConfig, LogContext } from '../../common/interfaces'; | ||
|
|
||
| @injectable() | ||
| export class ExtractableCall { | ||
| private readonly logContext: LogContext; | ||
| private readonly extractable: string; | ||
|
|
||
| public constructor( | ||
| @inject(SERVICES.CONFIG) private readonly config: IConfig, | ||
| @inject(SERVICES.LOGGER) private readonly logger: Logger, | ||
| @inject(SERVICES.TRACER) public readonly tracer: Tracer | ||
| ) { | ||
| this.extractable = this.config.get<string>('externalServices.extractable'); | ||
| this.logContext = { | ||
| fileName: __filename, | ||
| class: ExtractableCall.name, | ||
| }; | ||
| } | ||
|
|
||
| @withSpanAsyncV4 | ||
| public async isExtractableRecordExists(recordName: string): Promise<boolean> { | ||
| const logContext = { ...this.logContext, function: this.isExtractableRecordExists.name }; | ||
| this.logger.debug({ msg: `Checking record '${recordName}' in extractable service`, logContext }); | ||
|
|
||
| try { | ||
| const response = await axios.get(`${this.extractable}/records/${recordName}`, { | ||
| validateStatus: () => true, | ||
| }); | ||
|
|
||
| if (response.status === StatusCodes.OK) { | ||
| this.logger.debug({ msg: `Record '${recordName}' exists in extractable`, logContext }); | ||
| return true; | ||
| } | ||
|
|
||
| if (response.status === StatusCodes.NOT_FOUND) { | ||
| this.logger.debug({ msg: `Record '${recordName}' does not exist in extractable`, logContext }); | ||
| return false; | ||
| } | ||
|
|
||
| this.logger.error({ msg: `Unexpected status from extractable: ${response.status}`, logContext, status: response.status }); | ||
|
|
||
| throw new AppError('extractable', StatusCodes.INTERNAL_SERVER_ERROR, 'Unexpected response from extractable service', true); | ||
| } catch (error) { | ||
| this.logger.error({ msg: 'Error occurred during isExtractableRecordExists call', recordName, logContext, err: error }); | ||
|
|
||
| if (error instanceof AppError) { | ||
| throw error; | ||
| } | ||
|
|
||
| throw new AppError('extractable', StatusCodes.INTERNAL_SERVER_ERROR, 'Failed to query extractable service', true); | ||
| } | ||
| } | ||
| } |
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.