Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
path: root/vendor/league/oauth2-client/src/Exception/IDPException.php
blob: 668a7e7fae09d90bf4ee41de551814734bd7dbf1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<?php

namespace League\OAuth2\Client\Exception;

class IDPException extends \Exception
{
    protected $result;

    public function __construct($result)
    {
        if (!empty($result['error']) && is_array($result['error'])) {
            // Error response is wrapped in a top entity type, JSON:API style.
            $result = $result['error'];
        }

        $this->result = $result;

        $code = isset($result['code']) ? $result['code'] : 0;

        if (isset($result['error']) && $result['error'] !== '') {
            // OAuth 2.0 Draft 10 style
            $message = $result['error'];
        } elseif (isset($result['message']) && $result['message'] !== '') {
            // cURL style
            $message = $result['message'];
        } else {
            $message = 'Unknown Error.';
        }

        parent::__construct($message, $code);
    }

    public function getResponseBody()
    {
        return $this->result;
    }

    public function getType()
    {
        $result = 'Exception';

        if (isset($this->result['error'])) {
            $message = $this->result['error'];

            if (is_string($message)) {
                // OAuth 2.0 Draft 10 style
                $result = $message;
            }
        }

        return $result;
    }

    /**
     * To make debugging easier.
     *
     * @return string The string representation of the error.
     */
    public function __toString()
    {
        $str = $this->getType().': ';

        if ($this->code != 0) {
            $str .= $this->code.': ';
        }

        return $str.$this->message;
    }
}