addressed comments

Signed-off-by: Fredrik Adelöw <freben@gmail.com>
This commit is contained in:
Fredrik Adelöw
2026-02-10 17:31:41 +01:00
parent 80905b382f
commit 5399f1c7b5
2 changed files with 13 additions and 3 deletions
+4 -2
View File
@@ -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
@@ -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 = {