Skip to content

Commit 85ab74a

Browse files
michelle0927joy-chanboop
authored andcommitted
Elmah.io - add error handling and alert prop (PipedreamHQ#17032)
* add error handling and alert prop * pnpm-lock.yaml * updates
1 parent f9e6c17 commit 85ab74a

File tree

4 files changed

+50
-21
lines changed

4 files changed

+50
-21
lines changed

components/elmah_io/elmah_io.app.mjs

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,22 @@
1-
import { axios } from "@pipedream/platform";
1+
import {
2+
axios, ConfigurationError,
3+
} from "@pipedream/platform";
24

35
export default {
46
type: "app",
57
app: "elmah_io",
68
propDefinitions: {
79
logId: {
810
label: "Log ID",
9-
description: "The ID of the log",
11+
description: "The ID of the log. Requires that your api key have the `logs_read` permission.",
1012
type: "string",
1113
async options() {
1214
const logs = await this.getLogs();
1315

14-
return logs.map((log) => ({
16+
return logs?.map((log) => ({
1517
label: log.name,
1618
value: log.id,
17-
}));
19+
})) || [];
1820
},
1921
},
2022
},
@@ -28,14 +30,22 @@ export default {
2830
async _makeRequest({
2931
$ = this, path, ...args
3032
}) {
31-
return axios($, {
32-
...args,
33-
url: `${this._apiUrl()}${path}`,
34-
params: {
35-
...args?.params,
36-
api_key: this._apiKey(),
37-
},
38-
});
33+
try {
34+
return await axios($, {
35+
...args,
36+
url: `${this._apiUrl()}${path}`,
37+
params: {
38+
...args?.params,
39+
api_key: this._apiKey(),
40+
},
41+
});
42+
} catch (error) {
43+
if (error.response?.status === 401) {
44+
console.log(error);
45+
throw new ConfigurationError(`${error.response.data.title} ${error.response.data.detail}`);
46+
}
47+
throw error;
48+
}
3949
},
4050
async getLogs(args = {}) {
4151
return this._makeRequest({

components/elmah_io/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pipedream/elmah_io",
3-
"version": "0.0.4",
3+
"version": "0.0.5",
44
"description": "Pipedream elmah.io Components",
55
"main": "elmah_io.app.mjs",
66
"keywords": [
@@ -14,6 +14,6 @@
1414
"access": "public"
1515
},
1616
"dependencies": {
17-
"@pipedream/platform": "^1.2.0"
17+
"@pipedream/platform": "^3.1.0"
1818
}
1919
}

components/elmah_io/sources/new-error/new-error.mjs

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ import elmah_io from "../../elmah_io.app.mjs";
22
import constants from "../common/constants.mjs";
33
import { DEFAULT_POLLING_SOURCE_TIMER_INTERVAL } from "@pipedream/platform";
44

5-
const QUERY = "isNew:true AND (severity:Error OR severity:Fatal)";
5+
const QUERY = "severity:Error OR severity:Fatal";
66

77
export default {
88
name: "New Error",
9-
version: "0.0.3",
9+
version: "0.0.4",
1010
key: "elmah_io-new-error",
11-
description: "Emit new event on each new error",
11+
description: "Emit new event on each new error. [See the documentation](https://api.elmah.io/swagger/index.html#/Messages/Messages_GetAll)",
1212
type: "source",
1313
dedupe: "unique",
1414
props: {
@@ -26,20 +26,25 @@ export default {
2626
"logId",
2727
],
2828
},
29+
alert: {
30+
type: "alert",
31+
alertType: "info",
32+
content: "Note: This source requires that your api key have the `logs_read` and `messages_read` permissions.",
33+
},
2934
},
3035
methods: {
3136
emitEvent(event) {
3237
this.$emit(event, {
3338
id: event.id,
34-
summary: `New error with id ${event.id}`,
39+
summary: `New error with ID ${event.id}`,
3540
ts: Date.parse(event.dateTime),
3641
});
3742
},
3843
_setLastEventDatetime(datetime) {
3944
this.db.set("lastEventDatetime", datetime);
4045
},
4146
_getLastEventDatetime() {
42-
this.db.get("lastEventDatetime");
47+
return this.db.get("lastEventDatetime");
4348
},
4449
},
4550
hooks: {
@@ -52,11 +57,17 @@ export default {
5257
},
5358
});
5459

60+
if (!messages.length) {
61+
return;
62+
}
63+
5564
messages.forEach(this.emitEvent);
65+
this._setLastEventDatetime(messages[0].dateTime);
5666
},
5767
},
5868
async run() {
5969
let page = 0;
70+
const lastEventDatetime = this._getLastEventDatetime();
6071

6172
while (page >= 0) {
6273
const messages = await this.elmah_io.getMessages({
@@ -65,10 +76,18 @@ export default {
6576
pageIndex: page,
6677
pageSize: constants.DEFAULT_PAGE_SIZE,
6778
query: QUERY,
79+
from: lastEventDatetime
80+
? lastEventDatetime
81+
: undefined,
6882
},
6983
});
7084

85+
if (!messages.length) {
86+
return;
87+
}
88+
7189
messages.forEach(this.emitEvent);
90+
this._setLastEventDatetime(messages[0].dateTime);
7291

7392
page++;
7493

pnpm-lock.yaml

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)