diff --git a/plugins/events-backend-module-google-pubsub/config.d.ts b/plugins/events-backend-module-google-pubsub/config.d.ts index b6d3df633d..b70681f61a 100644 --- a/plugins/events-backend-module-google-pubsub/config.d.ts +++ b/plugins/events-backend-module-google-pubsub/config.d.ts @@ -14,6 +14,8 @@ * limitations under the License. */ +import { FilterPredicate } from '@backstage/filter-predicates'; + export interface Config { events?: { modules?: { @@ -96,7 +98,7 @@ export interface Config { * 'message.data.action': { $in: ['created', 'deleted'] } * ``` */ - filter?: object; + filter?: FilterPredicate; /** * Pub/Sub message attributes are by default copied to the event @@ -190,7 +192,7 @@ export interface Config { * 'event.eventPayload.action': { $in: ['created', 'deleted'] } * ``` */ - filter?: object; + filter?: FilterPredicate; /** * Event metadata fields are by default copied to the Pub/Sub diff --git a/plugins/events-backend-module-google-pubsub/src/GooglePubSubConsumingEventPublisher/GooglePubSubConsumingEventPublisher.ts b/plugins/events-backend-module-google-pubsub/src/GooglePubSubConsumingEventPublisher/GooglePubSubConsumingEventPublisher.ts index ae7b7e57f5..12f7225da1 100644 --- a/plugins/events-backend-module-google-pubsub/src/GooglePubSubConsumingEventPublisher/GooglePubSubConsumingEventPublisher.ts +++ b/plugins/events-backend-module-google-pubsub/src/GooglePubSubConsumingEventPublisher/GooglePubSubConsumingEventPublisher.ts @@ -19,7 +19,9 @@ import { RootConfigService, RootLifecycleService, } from '@backstage/backend-plugin-api'; +import { ForwardedError } from '@backstage/errors'; import { EventParams, EventsService } from '@backstage/plugin-events-node'; +import { JsonValue } from '@backstage/types'; import { Message, PubSub, Subscription } from '@google-cloud/pubsub'; import { Counter, metrics } from '@opentelemetry/api'; import { readSubscriptionTasksFromConfig } from './config'; @@ -197,7 +199,13 @@ export class GooglePubSubConsumingEventPublisher { message: Message, task: SubscriptionTask, ): EventParams | undefined { - const eventPayload = JSON.parse(message.data.toString()); + let eventPayload: JsonValue; + try { + eventPayload = JSON.parse(message.data.toString()); + } catch (error) { + throw new ForwardedError('Payload was not valid JSON', error); + } + const attributes = message.attributes; const context: MessageContext = {