Skip to content

Elmah.io - add error handling and alert prop #17032

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 11, 2025
Merged
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
34 changes: 22 additions & 12 deletions components/elmah_io/elmah_io.app.mjs
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
import { axios } from "@pipedream/platform";
import {
axios, ConfigurationError,
} from "@pipedream/platform";

export default {
type: "app",
app: "elmah_io",
propDefinitions: {
logId: {
label: "Log ID",
description: "The ID of the log",
description: "The ID of the log. Requires that your api key have the `logs_read` permission.",
type: "string",
async options() {
const logs = await this.getLogs();

return logs.map((log) => ({
return logs?.map((log) => ({
label: log.name,
value: log.id,
}));
})) || [];
},
},
},
Expand All @@ -28,14 +30,22 @@ export default {
async _makeRequest({
$ = this, path, ...args
}) {
return axios($, {
...args,
url: `${this._apiUrl()}${path}`,
params: {
...args?.params,
api_key: this._apiKey(),
},
});
try {
return await axios($, {
...args,
url: `${this._apiUrl()}${path}`,
params: {
...args?.params,
api_key: this._apiKey(),
},
});
} catch (error) {
if (error.response?.status === 401) {
console.log(error);
throw new ConfigurationError(`${error.response.data.title} ${error.response.data.detail}`);
}
throw error;
}
},
async getLogs(args = {}) {
return this._makeRequest({
Expand Down
4 changes: 2 additions & 2 deletions components/elmah_io/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pipedream/elmah_io",
"version": "0.0.4",
"version": "0.0.5",
"description": "Pipedream elmah.io Components",
"main": "elmah_io.app.mjs",
"keywords": [
Expand All @@ -14,6 +14,6 @@
"access": "public"
},
"dependencies": {
"@pipedream/platform": "^1.2.0"
"@pipedream/platform": "^3.1.0"
}
}
29 changes: 24 additions & 5 deletions components/elmah_io/sources/new-error/new-error.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
import constants from "../common/constants.mjs";
import { DEFAULT_POLLING_SOURCE_TIMER_INTERVAL } from "@pipedream/platform";

const QUERY = "isNew:true AND (severity:Error OR severity:Fatal)";
const QUERY = "severity:Error OR severity:Fatal";

export default {
name: "New Error",
version: "0.0.3",
version: "0.0.4",
key: "elmah_io-new-error",
description: "Emit new event on each new error",
description: "Emit new event on each new error. [See the documentation](https://api.elmah.io/swagger/index.html#/Messages/Messages_GetAll)",
type: "source",
dedupe: "unique",
props: {
Expand All @@ -26,20 +26,25 @@
"logId",
],
},
alert: {

Check warning on line 29 in components/elmah_io/sources/new-error/new-error.mjs

View workflow job for this annotation

GitHub Actions / Lint Code Base

Component prop alert must have a description. See https://pipedream.com/docs/components/guidelines/#props

Check warning on line 29 in components/elmah_io/sources/new-error/new-error.mjs

View workflow job for this annotation

GitHub Actions / Lint Code Base

Component prop alert must have a label. See https://pipedream.com/docs/components/guidelines/#props
type: "alert",
alertType: "info",
content: "Note: This source requires that your api key have the `logs_read` and `messages_read` permissions.",
},
},
methods: {
emitEvent(event) {
this.$emit(event, {
id: event.id,
summary: `New error with id ${event.id}`,
summary: `New error with ID ${event.id}`,
ts: Date.parse(event.dateTime),
});
},
_setLastEventDatetime(datetime) {
this.db.set("lastEventDatetime", datetime);
},
_getLastEventDatetime() {
this.db.get("lastEventDatetime");
return this.db.get("lastEventDatetime");
},
},
hooks: {
Expand All @@ -52,11 +57,17 @@
},
});

if (!messages.length) {
return;
}

messages.forEach(this.emitEvent);
this._setLastEventDatetime(messages[0].dateTime);
},
},
async run() {
let page = 0;
const lastEventDatetime = this._getLastEventDatetime();

while (page >= 0) {
const messages = await this.elmah_io.getMessages({
Expand All @@ -65,10 +76,18 @@
pageIndex: page,
pageSize: constants.DEFAULT_PAGE_SIZE,
query: QUERY,
from: lastEventDatetime
? lastEventDatetime
: undefined,
},
});

if (!messages.length) {
return;
}

messages.forEach(this.emitEvent);
this._setLastEventDatetime(messages[0].dateTime);

page++;

Expand Down
21 changes: 9 additions & 12 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading