You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We have a Monolog/Slack "webhook" implementation in our project. It works fine except when you don't have a webhook url
In my local environment I don't immediately have a Slack webhookurl. These are managed by Slack admins of our company so I can't just create one myself.
But the project requires one in the monolog config.
To address your issue, you're correct that the root cause of the crash stems from the fact that the webhook_url is required by the SlackWebhookHandler in Monolog. If it's left empty or not properly configured in your environment, the handler attempts to send a request, leading to a curl error. There are a few potential solutions to make this more flexible and avoid crashes in environments where a valid Slack webhook URL is not available.
Posible Solution:
Use Environment Variable Default Value. If the environment variable is not set or left empty, you could set a default value to prevent Monolog from trying to send data. You could modify the webhook_url in the Monolog configuration file to check if the environment variable exists and fallback to a default empty value or null.
monolog:
channels:
- slack_error
handlers:
slack_error:
type: slackwebhook
webhook_url: '%env(SLACK_ERROR_WEBHOOK_URL)%' # Ensure this is set or falls back to a blank URL.
channel: '%env(SLACK_ERROR_CHANNEL)%'
bot_name: '%env(SLACK_BOT_NAME)%'
icon_emoji: '%env(SLACK_EMOJI)%'
level: '%env(SLACK_ERROR_LEVEL)%'
include_extra: true
We have a Monolog/Slack "webhook" implementation in our project. It works fine except when you don't have a webhook url
In my local environment I don't immediately have a Slack webhookurl. These are managed by Slack admins of our company so I can't just create one myself.
But the project requires one in the monolog config.
If I leave it empty, my whole project crashes with a curl error in Handler/SlackWebhookHandler.php line 110
Is there an option to disable it?
What I currently did is setting the level
level: emergency
This is the highest level and I guess it currently never gets thrown.
Solution:
A solution for this bundle can be that if the webhookurl is left empty, no curl will get called
Another solution is adding an option
enabled: false
So te developer can decide if its enabled in his environment or not
The text was updated successfully, but these errors were encountered: