-
Notifications
You must be signed in to change notification settings - Fork 117
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revert "fix: improve error handling for webhook v2" (#4063)
- Loading branch information
Showing
12 changed files
with
24 additions
and
77 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
35 changes: 10 additions & 25 deletions
35
src/controllers/util/conversionStrategies/strategyV2ToV0.ts
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 |
---|---|---|
@@ -1,32 +1,17 @@ | ||
import { TransformationError } from '@rudderstack/integrations-lib'; | ||
import { SourceInputConversionResult, SourceInputV2 } from '../../../types'; | ||
import { VersionConversionStrategy } from './abstractions'; | ||
import { ErrorMessages } from '../../../constants'; | ||
|
||
export class StrategyV2ToV0 extends VersionConversionStrategy<SourceInputV2, NonNullable<unknown>> { | ||
convert(sourceEvents: SourceInputV2[]): SourceInputConversionResult<NonNullable<unknown>>[] { | ||
return sourceEvents.map((sourceEvent) => this.convertSingleEvent(sourceEvent)); | ||
} | ||
|
||
private convertSingleEvent( | ||
sourceEvent: SourceInputV2, | ||
): SourceInputConversionResult<NonNullable<unknown>> { | ||
try { | ||
const v0Event = this.parseRequestBody(sourceEvent.request.body); | ||
return { output: v0Event }; | ||
} catch (err) { | ||
const conversionError = | ||
err instanceof TransformationError ? err : new Error('error converting v2 to v0 spec'); | ||
|
||
return { conversionError }; | ||
} | ||
} | ||
|
||
private parseRequestBody(body: string): NonNullable<unknown> { | ||
try { | ||
return JSON.parse(body); | ||
} catch (err) { | ||
throw new TransformationError(ErrorMessages.JSONParseError); | ||
} | ||
return sourceEvents.map((sourceEvent) => { | ||
try { | ||
const v0Event = JSON.parse(sourceEvent.request.body); | ||
return { output: v0Event }; | ||
} catch (err) { | ||
const conversionError = | ||
err instanceof Error ? err : new Error('error converting v2 to v0 spec'); | ||
return { conversionError }; | ||
} | ||
}); | ||
} | ||
} |
34 changes: 10 additions & 24 deletions
34
src/controllers/util/conversionStrategies/strategyV2ToV1.ts
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 |
---|---|---|
@@ -1,31 +1,17 @@ | ||
import { TransformationError } from '@rudderstack/integrations-lib'; | ||
import { SourceInput, SourceInputConversionResult, SourceInputV2 } from '../../../types'; | ||
import { VersionConversionStrategy } from './abstractions'; | ||
|
||
export class StrategyV2ToV1 extends VersionConversionStrategy<SourceInputV2, SourceInput> { | ||
convert(sourceEvents: SourceInputV2[]): SourceInputConversionResult<SourceInput>[] { | ||
return sourceEvents.map((sourceEvent) => this.convertSingleEvent(sourceEvent)); | ||
} | ||
|
||
private convertSingleEvent(sourceEvent: SourceInputV2): SourceInputConversionResult<SourceInput> { | ||
try { | ||
const v1Event = { | ||
event: this.parseRequestBody(sourceEvent.request.body), | ||
source: sourceEvent.source, | ||
}; | ||
return { output: v1Event }; | ||
} catch (err) { | ||
const conversionError = | ||
err instanceof TransformationError ? err : new Error('error converting v2 to v1 spec'); | ||
return { conversionError }; | ||
} | ||
} | ||
|
||
private parseRequestBody(body: string): NonNullable<unknown> { | ||
try { | ||
return JSON.parse(body); | ||
} catch (err) { | ||
throw new TransformationError('Malformed JSON in request body'); | ||
} | ||
return sourceEvents.map((sourceEvent) => { | ||
try { | ||
const v1Event = { event: JSON.parse(sourceEvent.request.body), source: sourceEvent.source }; | ||
return { output: v1Event }; | ||
} catch (err) { | ||
const conversionError = | ||
err instanceof Error ? err : new Error('error converting v2 to v1 spec'); | ||
return { conversionError }; | ||
} | ||
}); | ||
} | ||
} |
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
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
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
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
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
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
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
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
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