Skip to content

Commit

Permalink
fix(Rollbar): ignore P1-meter EHOSTUNREACH and ECONNRESET errors
Browse files Browse the repository at this point in the history
Closes #9, closes #33, closes #39, closes #40, closes #41, closes #42.
  • Loading branch information
jdbruijn committed Jun 17, 2023
1 parent ed1792b commit 41c7d9a
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/p1-meter/api.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import axios, {type AxiosInstance} from 'axios';
import axios, {AxiosError, type AxiosInstance} from 'axios';
import {type z} from 'zod';
import {type Config} from '../config.js';
import {DetailedError} from '../error.js';
import logger from '../logger.js';
import rollbar from '../rollbar.js';
import * as models from './models/index.js';
import {type Telegram} from './telegram/model.js';
import parse from './telegram/parse.js';
Expand All @@ -12,6 +14,19 @@ class P1Meter {
constructor(url: Config['meterApiUrl']) {
// eslint-disable-next-line @typescript-eslint/naming-convention
this._axios = axios.create({baseURL: url});
this._axios.interceptors.response.use(
(response) => response,
(error) => {
logger.error(error, error instanceof Error ? error.message : undefined);
if (
error instanceof Error &&
(!(error instanceof AxiosError) ||
['EHOSTUNREACH', 'ECONNRESET'].every((code) => error.code !== code))
) {
rollbar.error(error, error.message);
}
},
);
}

async basicInformation(): Promise<models.BasicInformation> {
Expand Down

0 comments on commit 41c7d9a

Please sign in to comment.