Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion functions/src/bills/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { isString } from "lodash"
import { db } from "../firebase"
import { createSearchIndexer } from "../search"
import { Bill, BillTopic } from "./types"
import { logger } from "firebase-functions"

export const {
syncToSearchIndex: syncBillToSearchIndex,
Expand Down Expand Up @@ -42,7 +43,7 @@ export const {
convert: data => {
const validation = Bill.validateWithDefaults(data)
if (!validation.success) {
console.error(data, validation.message, validation.details)
logger.error(data, validation.message, validation.details)
}
const bill = Bill.checkWithDefaults(data)

Expand Down
6 changes: 3 additions & 3 deletions functions/src/notifications/deliverNotifications.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const getVerifiedUserEmail = async (uid: string) => {
return null
}
} catch (error) {
console.error(`Error getting user email for UID ${uid}:`, error)
functions.logger.error(`Error getting user email for UID ${uid}:`, error)
return null
}
}
Expand Down Expand Up @@ -191,7 +191,7 @@ export const buildDigestData = async (
bill.opposeCount++
break
default:
console.error(`Unknown position: ${notification.position}`)
functions.logger.error(`Unknown position: ${notification.position}`)
break
}
} else {
Expand Down Expand Up @@ -241,7 +241,7 @@ export const buildDigestData = async (
bq.opposeCount++
break
default:
console.error(`Unknown position: ${notification.position}`)
functions.logger.error(`Unknown position: ${notification.position}`)
break
}
} else {
Expand Down
3 changes: 2 additions & 1 deletion functions/src/notifications/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
} from "date-fns"

import { JSDOM } from "jsdom"
import { logger } from "firebase-functions"

export const getNextDigestAt = (notificationFrequency: Frequency) => {
const now = startOfDay(new Date())
Expand All @@ -31,7 +32,7 @@ export const getNextDigestAt = (notificationFrequency: Frequency) => {
nextDigestAt = null
break
default:
console.error(`Unknown notification frequency: ${notificationFrequency}`)
logger.error(`Unknown notification frequency: ${notificationFrequency}`)
break
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export const populateBallotQuestionNotificationEventsHandler = async (
context: functions.EventContext
) => {
if (!snapshot.after.exists) {
console.error("New snapshot does not exist")
functions.logger.error("New snapshot does not exist")
return
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const populateBillHistoryNotificationEvents = functions.firestore
.document("/generalCourts/{court}/bills/{billId}")
.onWrite(async (snapshot, context) => {
if (!snapshot.after.exists) {
console.error("New snapshot does not exist")
functions.logger.error("New snapshot does not exist")
return
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const populateTestimonySubmissionNotificationEvents = functions.firestore
.document("/users/{userId}/publishedTestimony/{testimonyId}")
.onWrite(async (snapshot, context) => {
if (!snapshot.after.exists) {
console.error("New snapshot does not exist")
functions.logger.error("New snapshot does not exist")
return
}

Expand Down
2 changes: 1 addition & 1 deletion functions/src/notifications/publishNotifications.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ export const publishNotifications = functions.firestore
| undefined

if (!topic) {
console.error("Invalid topic data:", topic)
functions.logger.error("Invalid topic data:", topic)
return
}

Expand Down
8 changes: 4 additions & 4 deletions functions/src/search/SearchIndexer.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Change } from "firebase-functions"
import { Change, logger } from "firebase-functions"
import { isEqual, last } from "lodash"
import hash from "object-hash"
import Collection from "typesense/lib/Typesense/Collection"
Expand Down Expand Up @@ -43,7 +43,7 @@ export class SearchIndexer {
try {
return this.config.filter(data)
} catch (error) {
console.error("Filter function threw", error)
logger.error("Filter function threw", error)
return false
}
}
Expand Down Expand Up @@ -141,7 +141,7 @@ export class SearchIndexer {
const doc = convert(data)
acc.push(doc)
} catch (error: any) {
console.error(`Failed to convert document: ${error.message}`)
logger.error(`Failed to convert document: ${error.message}`)
}
return acc
}, [] as any[])
Expand All @@ -151,7 +151,7 @@ export class SearchIndexer {
} catch (e) {
if (e instanceof ImportError) {
const results = e.importResults as unknown as ImportResponse[]
console.error(
logger.error(
results
.map(
r =>
Expand Down
3 changes: 2 additions & 1 deletion functions/src/subscriptions/removeTopicSubscription.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Database } from "../types"
import { UserRecord } from "firebase-admin/auth"
import { TopicSubscription } from "./types"
import { logger } from "firebase-functions"

export const removeTopicSubscription = async ({
user,
Expand All @@ -21,6 +22,6 @@ export const removeTopicSubscription = async ({
.doc(topicName)
.delete()
} catch (error: any) {
console.error("Error removing topic subscription: ", error)
logger.error("Error removing topic subscription: ", error)
}
}
3 changes: 2 additions & 1 deletion functions/src/subscriptions/subscribeToTestimonyTopic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Database } from "../types"
import { UserRecord } from "firebase-admin/auth"
import { TopicSubscription } from "./types"
import { addTopicSubscription } from "./addTopicSubscription"
import { logger } from "firebase-functions"

export const subscribeToTestimonyTopic = async ({
user,
Expand Down Expand Up @@ -40,6 +41,6 @@ export const subscribeToTestimonyTopic = async ({
console.log("Debug: Subscription added successfully")
} catch (error) {
// Debug: Log any errors
console.error("Debug: Error in subscribeToOrgTopic", error)
logger.error("Debug: Error in subscribeToTestimonyTopic", error)
}
}
2 changes: 1 addition & 1 deletion functions/src/subscriptions/unfollowBill.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export const unfollowBill = functions.https.onCall(async (data, context) => {
await unsubscribeToBillTopic({ user, billLookup, db })
return { status: "success", message: "Bill subscription removed" }
} catch (error: any) {
console.error(
functions.logger.error(
`Error in unfollowBill for user ${context.auth.uid}:`,
error.stack
)
Expand Down
3 changes: 2 additions & 1 deletion functions/src/subscriptions/unsubscribeToBillTopic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Database } from "../types"
import { UserRecord } from "firebase-admin/auth"
import { TopicSubscription } from "./types"
import { removeTopicSubscription } from "./removeTopicSubscription"
import { logger } from "firebase-functions"

export const unsubscribeToBillTopic = async ({
user,
Expand All @@ -28,7 +29,7 @@ export const unsubscribeToBillTopic = async ({

await removeTopicSubscription({ user, subscriptionData, db })
} catch (error) {
console.error("Error in unsubscribeToBillTopic:", error)
logger.error("Error in unsubscribeToBillTopic:", error)
throw error
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Database } from "../types"
import { UserRecord } from "firebase-admin/auth"
import { TopicSubscription } from "./types"
import { removeTopicSubscription } from "./removeTopicSubscription"
import { logger } from "firebase-functions"

export const unsubscribeToTestimonyTopic = async ({
user,
Expand Down Expand Up @@ -40,6 +41,6 @@ export const unsubscribeToTestimonyTopic = async ({
console.log("Debug: Subscription removed successfully")
} catch (error) {
// Debug: Log any errors
console.error("Debug: Error in unsubscribeToOrgTopic", error)
logger.error("Debug: Error in unsubscribeToTestimonyTopic", error)
}
}
3 changes: 2 additions & 1 deletion functions/src/testimony/search.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { db } from "../firebase"
import { createSearchIndexer } from "../search"
import { Testimony, TestimonySearchRecord } from "./types"
import { logger } from "firebase-functions"

export const {
syncToSearchIndex: syncTestimonyToSearchIndex,
Expand Down Expand Up @@ -31,7 +32,7 @@ export const {
convert: data => {
const validation = Testimony.validateWithDefaults(data)
if (!validation.success) {
console.error(data, validation.message, validation.details)
logger.error(data, validation.message, validation.details)
throw new Error("Invalid testimony")
}
const testimony = validation.value
Expand Down
Loading