replace error instances with AppError

This commit is contained in:
Alex Holliday committed 2026-07-24 10:49:39 -07:00
1 parent 25d81f4238
commit 86eeda3f0e
3 files changed
+8 -3

No files matched your search

@@ -21,6 +21,7 @@ import { toStringId, toDateString } from "@/utils/mongoMappers.js";
import { getHardwareUpChecks, getHardwareStats, getHardwareTotalChecks } from "@/domain/checks/check.hardware.aggregations.js";
import { DateRange } from "@/types/query.js";
import { AppError } from "@/utils/AppError.js";
const SERVICE_NAME = "StatusService";
@@ -181,7 +182,12 @@ class MongoChecksRepository implements IChecksRepository {
// Map id to _id for MongoDB storage
const { id, metadata, ...rest } = check;
if (!metadata || !metadata.monitorId || !metadata.teamId) {
throw new Error(`Check must have valid metadata with monitorId and teamId. Got: ${JSON.stringify({ id, metadata })}`);
throw new AppError({
message: `Check must have valid metadata with monitorId and teamId. Got: ${JSON.stringify({ id, metadata })}`,
status: 500,
service: SERVICE_NAME,
method: "toDocument",
});
}
return {
_id: id ? new mongoose.Types.ObjectId(id) : new mongoose.Types.ObjectId(),
@@ -22,7 +22,6 @@ export interface IGeoChecksRepository {
rowsPerPage: number,
continents?: GeoContinent[]
): Promise<FlatGeoChecksQueryResult>;
findByMonitorIdAndDateRange(monitorId: string, startDate: Date, endDate: Date): Promise<GeoCheck[]>;
findGroupedByMonitorIdAndDateRange(monitorId: string, DateRange: DateRange, continents?: GeoContinent[]): Promise<GroupedGeoCheck[]>;
deleteByMonitorId(monitorId: string): Promise<number>;
deleteByTeamId(teamId: string): Promise<number>;
@@ -71,7 +71,7 @@ class MongoUsersRepository implements IUsersRepository {
findById = async (id: string) => {
const user = await UserModel.findById(id).select("-password").select("-profileImage");
if (!user) {
throw new Error("User not found");
throw new AppError({ message: "User not found", service: SERVICE_NAME, status: 404 });
}
return this.toEntity(user);