0

I'm attempting to send a CURL to my Slack channel whenever an Artisan command fails in any of one of my scripts (it runs hourly so I want to make sure we know what's causing these errors at any point in the night), but it doesn't want to send the CURL. I've confirmed other things work, but it just doesn't seem to want to send it right now.

Here's the code to send it, it's not much

} catch(\Throwable $e) {
        $message = "Found an error with the message " . $e->getMessage() . " , The function ResetBars did not finish.";
        Curl::to('https://hooks.slack.com/services/MYHOOK/RAWR/NOSEE')
        ->withContentType('application/json')->withData('{"text":"'.$message.'"}')->post();
      }

No idea why that doesn't work, I'm using a PHP Curl library, but it does the same thing as the regular cURL

I can include the rest of the code but it really doesn't matter as this is the only part not working

Edit: Full Code

public function handle() {
      //This function updates a bars hours after they're closed to the next day's hours
      //First we remove unwanted barDays
      try {
        $this->cleanBar();
        $this->cleanBarDays();
        $this->fixBarStats();
        $this->fixPromoStats();
        $this->cleanUserBars();
        $count = count(barDays::all()) + count(promoStats::where('timeLeft', NULL)->get()) + count(User::where('bar_id', '!=', NULL)->get()) + count(barStats::where('timeLeft', NULL)->get());
        $Bars = Bars::all();
        $this->output->progressStart(count($Bars));
        foreach($Bars as $Bar) {
          $now = Carbon::now()->setTimezone($Bar->timezone);
          $hours = $Bar->getHours();
          if($hours[0] === 'Closed') {
            $Bar->numPeople = 0;
            $Bar->hours = 'Closed';
            Bars::withoutSyncingToSearch(function() use($Bar) {
              $Bar->save();
            });
          } else {
            //Not closed, we check if the exploded hours followed the format
            $openHours = $hours[0];
            $closedHours = $hours[1];
            //Then we try to parse them, otherwise we catch the error to follow the culprit
            $open = Carbon::parse($openHours, $Bar->timezone);
            $closed = Carbon::parse($closedHours, $Bar->timezone);
            //If the bar is closed, we update the hours on the bar
            if(!$now->between($open, $closed)) {
              $Bar->updateHours();
              $Bar->numPeople = 0;
              //UPDATE BARSTATS HERE WITH BAR ID
              $barStats = barStats::where('bar_id', $Bar->id)->where('timeLeft', NULL)->get();
              foreach($barStats as $barStat) {
                $barStat->timeLeft = Carbon::now();
                $barStat->save();
              }
            } elseif($now->between($open, $closed)) {
              $Bar->updateHours();
            }
            Bars::withoutSyncingToSearch(function() use($Bar) {
              $Bar->save();
            });
          }
          $this->output->progressAdvance();
        }
        $this->output->progressFinish();
        Curl::to('https://hooks.slack.com/services/nuh uh/')
        ->withContentType('application/json')->withData('{"text":"Reset '.count($Bars).' Bars Hour\'s, '.$count.' number of miscellaneous models and reset number of people if closed."}')->post();
        return "Updated";
      } catch(Exception $e) {
        $message = "Found an error with the message " . $e->getMessage() . " , The function ResetBars did not finish.";
        Curl::to('https://hooks.slack.com/services/nope/')
        ->withContentType('application/json')->withData('{"text":"'.$message.'"}')->post();
      }
    }

Ignore the function calls at the top Thanks

  • Zach

1 Answer 1

0

Change:

catch(\Throwable $e) {
    $message = "Found an error with the message " . $e->getMessage() . " , The function ResetBars did not finish.";
    Curl::to('https://hooks.slack.com/services/MYHOOK/RAWR/NOSEE')
    ->withContentType('application/json')->withData('{"text":"'.$message.'"}')->post();
  }

To:

catch(Exception $e) {
    $message = "Found an error with the message " . $e->getMessage() . " , The function ResetBars did not finish.";
    Curl::to.....
  }
Sign up to request clarification or add additional context in comments.

14 Comments

} catch(Exception $e) { $message = "Found an error with the message " . $e->getMessage() . " , The function ResetBars did not finish."; Curl::to('https://hooks.slack.com/services/myhook') ->withContentType('application/json')->withData('{"text":"'.$message.'"}')->post(); }
Print something inside catch, to verify, plz.
I tried that already as well, I tried $output->error('test'); and it went through without issue to the console
Haha, your try{}catch() is not throwing an exception. Your code is fine. :).
Yessir, it won't make full sense but I will post it in main question
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.