LoginSignup
0
0

More than 3 years have passed since last update.

GuzzleHttpで401が返却されても例外をスローさせない

Last updated at Posted at 2019-11-11

Laravelから外部APIを呼ぶときにGuzzleHttpを使ってみた。
401エラーが返却されたときの情報を使って正常処理を続ける必要があったので、例外をスローさせない方法を調べてみたところ、[http_errors]パラメータにfalseを指定すると出来たので、メモ。

            $httpClient = new GuzzleHttp\Client();
            $response = $httpClient->request(
                'POST',
                $url,
                [
                    'headers' => $headers,
                    'json' => $params,
                    'http_errors' => false  // 401が返却されても例外をスローしない
                ]);

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0