Skip to content

Commit

Permalink
Merge pull request #25 from TheAppleFreak/Axios-error-fix
Browse files Browse the repository at this point in the history
Added option to address potentially random crashes from Axios. Added tests and updated dependencies as well.
  • Loading branch information
TheAppleFreak authored Apr 5, 2023
2 parents 317ed74 + 6d41e50 commit f706828
Show file tree
Hide file tree
Showing 10 changed files with 1,895 additions and 1,825 deletions.
22 changes: 22 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
// README at: https://github.com/devcontainers/templates/tree/main/src/typescript-node
{
"name": "Node.js & TypeScript",
// Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile
"image": "mcr.microsoft.com/devcontainers/typescript-node:0-18"

// Features to add to the dev container. More info: https://containers.dev/features.
// "features": {},

// Use 'forwardPorts' to make a list of ports inside the container available locally.
// "forwardPorts": [],

// Use 'postCreateCommand' to run commands after the container is created.
// "postCreateCommand": "yarn install",

// Configure tool-specific properties.
// "customizations": {},

// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
// "remoteUser": "root"
}
9 changes: 9 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"$schema": "http://json.schemastore.org/prettierrc",
"trailingComma": "none",
"tabWidth": 4,
"semi": true,
"singleQuote": false,
"bracketSpacing": true,
"printWidth": 88
}
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
# CHANGELOG

(all dates use the ISO-8601 format, which is YYYY/MM/DD)

## 2.3.0 (2023/4/5)

* Added an option (`emitAxiosErrors`) to enable or disable emitting errors if Axios throws an error. Previously, if Axios returned an error for any reason, this would emit an error, which if unhandled would be treated as an unhandled exception. This includes potentially transient issues, such as if Slack would return an error for any reason, including API outages or `429 Too Many Requests` errors. This option requires the user to explicitly opt into this behavior, and is `false` by default. This closes [Issue #24](https://github.com/TheAppleFreak/winston-slack-webhook-transport/issues/24). Thanks @jbojbo for bringing this to my attention!

When I had initially added the code that would do that, I was under the impression this would log the Slack error to Winston itself as an error, [but after rereading the relevant documentation](https://github.com/winstonjs/winston#awaiting-logs-to-be-written-in-winston) I realized this was not the case.
* Minor change to the `log()` function to make it an async function, which simplifies some minor aspects of unit testing. This should have no impact on using the transport within Winston.
* Updated tests to check the error handling behavior.
* Added new option to the type definitions.
* Added a Prettier script and prettierrc.
* Updated dependencies, and double checked to make sure everything continued to work this time.

## 2.2.3 (2023/3/3)

* Fixed a bug preventing the ability to filter log messages in the formatter. This change is courtesy of [Pull #23](https://github.com/TheAppleFreak/winston-slack-webhook-transport/pull/23), which closes [Issue #15](https://github.com/TheAppleFreak/winston-slack-webhook-transport/issues/15) in the process. Thanks @ArturAralin and @jbojbo!
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ logger.add(new SlackHook({ webhookUrl: "https://hooks.slack.com/services/xxx/xxx
* `username` - Overrides the webhook's default username. (Default: `undefined`)
* `iconEmoji` - An [emoji code string](https://www.webpagefx.com/tools/emoji-cheat-sheet/) to use in place of the default icon. (Interchangeable with `iconUrl`) (Default: `undefined`)
* `iconUrl` - An icon image URL string to use in place of the default icon. Interchangeable with `iconEmoji`. (Default: `undefined`)
* `emitAxiosErrors` - Enables or disables [emitting errors when Axios throws an error](https://github.com/winstonjs/winston#awaiting-logs-to-be-written-in-winston). This can occur if Slack returns a non-200 response code, such as `429 Too Many Requests`. When disabled, Slack errors will be silently dropped, [though if unhandled this can possibly lead to unexpected and transient crashes.](https://github.com/TheAppleFreak/winston-slack-webhook-transport/issues/24) Enable to handle those errors yourself. (Default: `false`)

### Message formatting

Expand Down
7 changes: 0 additions & 7 deletions __mocks__/axios.js

This file was deleted.

Loading

0 comments on commit f706828

Please sign in to comment.