Skip to content

Commit

Permalink
Revert "fix: improve error handling for webhook v2" (#4063)
Browse files Browse the repository at this point in the history
  • Loading branch information
sanpj2292 authored Feb 11, 2025
2 parents d795830 + 6d29785 commit 6fd8651
Show file tree
Hide file tree
Showing 12 changed files with 24 additions and 77 deletions.
5 changes: 0 additions & 5 deletions src/constants/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,6 @@ const HTTP_CUSTOM_STATUS_CODES = {
FILTERED: 298,
};

const ErrorMessages = {
JSONParseError: 'Malformed JSON in request body',
};

module.exports = {
EventType,
GENERIC_TRUE_VALUES,
Expand All @@ -68,5 +64,4 @@ module.exports = {
TraitsMapping,
WhiteListedTraits,
HTTP_CUSTOM_STATUS_CODES,
ErrorMessages,
};
35 changes: 10 additions & 25 deletions src/controllers/util/conversionStrategies/strategyV2ToV0.ts
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 src/controllers/util/conversionStrategies/strategyV2ToV1.ts
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 };
}
});
}
}
6 changes: 2 additions & 4 deletions src/controllers/util/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { TransformationError } from '@rudderstack/integrations-lib';
import { ErrorMessages } from '../../constants';
import {
Destination,
Metadata,
Expand Down Expand Up @@ -224,7 +222,7 @@ describe('adaptInputToVersion', () => {
implementationVersion: 'v0',
input: [
{
conversionError: new TransformationError(ErrorMessages.JSONParseError),
conversionError: new SyntaxError('Unexpected end of JSON input'),
},
],
};
Expand Down Expand Up @@ -323,7 +321,7 @@ describe('adaptInputToVersion', () => {
implementationVersion: 'v1',
input: [
{
conversionError: new TransformationError(ErrorMessages.JSONParseError),
conversionError: new SyntaxError('Unexpected end of JSON input'),
},
],
};
Expand Down
6 changes: 2 additions & 4 deletions src/services/source/nativeIntegration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { FetchHandler } from '../../helpers/fetchHandlers';
import { SourceService } from '../../interfaces/SourceService';
import {
ErrorDetailer,
ErrorDetailerOptions,
MetaTransferObject,
RudderMessage,
SourceInputConversionResult,
Expand All @@ -16,14 +15,13 @@ import { SourcePostTransformationService } from './postTransformation';
import logger from '../../logger';

export class NativeIntegrationSourceService implements SourceService {
public getTags(extraErrorDetails: ErrorDetailerOptions = {}): MetaTransferObject {
public getTags(): MetaTransferObject {
const metaTO = {
errorDetails: {
module: tags.MODULES.SOURCE,
implementation: tags.IMPLEMENTATIONS.NATIVE,
destinationId: 'Non determinable',
workspaceId: 'Non determinable',
...extraErrorDetails,
} as ErrorDetailer,
errorContext: '[Native Integration Service] Failure During Source Transform',
} as MetaTransferObject;
Expand All @@ -38,7 +36,7 @@ export class NativeIntegrationSourceService implements SourceService {
_requestMetadata: NonNullable<unknown>,
): Promise<SourceTransformationResponse[]> {
const sourceHandler = FetchHandler.getSourceHandler(sourceType, version);
const metaTO = this.getTags({ srcType: sourceType });
const metaTO = this.getTags();
const respList: SourceTransformationResponse[] = await Promise.all<FixMe>(
sourceEvents.map(async (sourceEvent) => {
try {
Expand Down
4 changes: 0 additions & 4 deletions src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -270,9 +270,6 @@ type ErrorDetailer = {
module: string;
implementation: string;
feature: string;
} & ErrorDetailerOptions;

type ErrorDetailerOptions = {
errorCategory?: string;
errorType?: string;
meta?: string;
Expand Down Expand Up @@ -393,7 +390,6 @@ export {
Connection,
Destination,
ErrorDetailer,
ErrorDetailerOptions,
MessageIdMetadataMap,
MetaTransferObject,
Metadata,
Expand Down
2 changes: 0 additions & 2 deletions test/integrations/sources/adjust/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@ export const data = [
errorCategory: 'transformation',
implementation: 'native',
module: 'source',
srcType: 'adjust',
workspaceId: 'Non determinable',
},
statusCode: 400,
Expand Down Expand Up @@ -177,7 +176,6 @@ export const data = [
errorCategory: 'transformation',
implementation: 'native',
module: 'source',
srcType: 'adjust',
workspaceId: 'Non determinable',
},
statusCode: 400,
Expand Down
1 change: 0 additions & 1 deletion test/integrations/sources/appsflyer/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -687,7 +687,6 @@ export const data = [
errorCategory: 'transformation',
implementation: 'native',
module: 'source',
srcType: 'appsflyer',
workspaceId: 'Non determinable',
},
statusCode: 400,
Expand Down
2 changes: 0 additions & 2 deletions test/integrations/sources/canny/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1573,7 +1573,6 @@ export const data = [
errorCategory: 'transformation',
implementation: 'native',
module: 'source',
srcType: 'canny',
workspaceId: 'Non determinable',
},
},
Expand Down Expand Up @@ -1651,7 +1650,6 @@ export const data = [
errorCategory: 'transformation',
implementation: 'native',
module: 'source',
srcType: 'canny',
workspaceId: 'Non determinable',
},
},
Expand Down
1 change: 0 additions & 1 deletion test/integrations/sources/gainsightpx/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -853,7 +853,6 @@ export const data = [
errorCategory: 'transformation',
implementation: 'native',
module: 'source',
srcType: 'gainsightpx',
workspaceId: 'Non determinable',
},
statusCode: 400,
Expand Down
2 changes: 0 additions & 2 deletions test/integrations/sources/iterable/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ export const data = [
errorCategory: 'transformation',
implementation: 'native',
module: 'source',
srcType: 'iterable',
workspaceId: 'Non determinable',
},
statusCode: 400,
Expand Down Expand Up @@ -146,7 +145,6 @@ export const data = [
errorCategory: 'transformation',
implementation: 'native',
module: 'source',
srcType: 'iterable',
workspaceId: 'Non determinable',
},
statusCode: 400,
Expand Down
3 changes: 0 additions & 3 deletions test/integrations/sources/shopify/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ const serverSideEventsScenarios = [
errorCategory: 'transformation',
implementation: 'native',
module: 'source',
srcType: 'shopify',
workspaceId: 'Non determinable',
},
statusCode: 400,
Expand Down Expand Up @@ -105,7 +104,6 @@ const serverSideEventsScenarios = [
errorCategory: 'transformation',
implementation: 'native',
module: 'source',
srcType: 'shopify',
workspaceId: 'Non determinable',
},
statusCode: 400,
Expand Down Expand Up @@ -150,7 +148,6 @@ const serverSideEventsScenarios = [
errorCategory: 'transformation',
implementation: 'native',
module: 'source',
srcType: 'shopify',
workspaceId: 'Non determinable',
},
statusCode: 400,
Expand Down

0 comments on commit 6fd8651

Please sign in to comment.