Skip to content

Commit

Permalink
don't crash on schema validation fail
Browse files Browse the repository at this point in the history
  • Loading branch information
GerritPlehn committed Dec 14, 2023
1 parent 65401ae commit 1d90360
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/crawl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export const crawlFronius = async () => {
try {
await crawlEndpoint(endpoint);
} catch (error) {
console.log(error);
console.error("Error while fetching endpoint", error);
}
}
};
8 changes: 7 additions & 1 deletion src/influx/inverter3P.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,13 @@ import { writeApi } from "./index.ts";
import { inverter3PSchema } from "../types/Inverter3P.ts";

export const writeInverter3P = async (rawData: unknown) => {
const data = inverter3PSchema.parse(rawData);
const input = inverter3PSchema.safeParse(rawData);

if (!input.success) {
console.warn("got unexpected data", input.error);
return;
}
const { data } = input;

const inverter3p = data.Body.Data;
const measurementTime = data.Head.Timestamp;
Expand Down
8 changes: 7 additions & 1 deletion src/influx/inverterCommon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,13 @@ import { writeApi } from "./index.ts";
import { inverterCommonSchema } from "../types/InverterCommon.ts";

export const writeInverterCommon = async (rawData: unknown) => {
const data = inverterCommonSchema.parse(rawData);
const input = inverterCommonSchema.safeParse(rawData);

if (!input.success) {
console.warn("got unexpected data", input.error);
return;
}
const { data } = input;

const invertercommon = data.Body.Data;
const measurementTime = data.Head.Timestamp;
Expand Down
8 changes: 7 additions & 1 deletion src/influx/inverterCumulation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,13 @@ import { writeApi } from "./index.ts";
import { inverterCumulationSchema } from "../types/InverterCumulation.ts";

export const writeInverterCumulation = async (rawData: unknown) => {
const data = inverterCumulationSchema.parse(rawData);
const input = inverterCumulationSchema.safeParse(rawData);

if (!input.success) {
console.warn("got unexpected data", input.error);
return;
}
const { data } = input;

const invertercumulation = data.Body.Data;
const measurementTime = data.Head.Timestamp;
Expand Down
8 changes: 7 additions & 1 deletion src/influx/meter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,13 @@ import { writeApi } from "./index.ts";
import { meterSchema } from "../types/Meter.ts";

export const writeMeter = async (rawData: unknown) => {
const data = meterSchema.parse(rawData);
const input = meterSchema.safeParse(rawData);

if (!input.success) {
console.warn("got unexpected data", input.error);
return;
}
const { data } = input;

const meter = data.Body.Data;
const measurementTime = data.Head.Timestamp;
Expand Down
8 changes: 7 additions & 1 deletion src/influx/powerFlow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,13 @@ import { writeApi } from "./index.ts";
import { powerFlowSchema } from "../types/PowerFlow";

export const writePowerFlow = async (rawData: unknown) => {
const data = powerFlowSchema.parse(rawData);
const input = powerFlowSchema.safeParse(rawData);

if (!input.success) {
console.warn("got unexpected data", input.error);
return;
}
const { data } = input;

const inverter = data.Body.Data.Inverters[1];
const site = data.Body.Data.Site;
Expand Down
8 changes: 7 additions & 1 deletion src/influx/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,13 @@ import { writeApi } from "./index.ts";
import { storageSchema } from "../types/Storage.ts";

export const writeStorage = async (rawData: unknown) => {
const data = storageSchema.parse(rawData);
const input = storageSchema.safeParse(rawData);

if (!input.success) {
console.warn("got unexpected data", input.error);
return;
}
const { data } = input;

const storage = data.Body.Data.Controller;
if (!storage) {
Expand Down

0 comments on commit 1d90360

Please sign in to comment.