Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 1
<?php declare(strict_types=1);
2
 
3
namespace EduSharingApiClient;
4
 
5
use Exception;
6
 
7
/**
8
 * Class AppAuthException
9
 *
10
 * Class that describes the handling of curl requests
11
 *
12
 * @author Torsten Simon   <simon@edu-sharing.net>
13
 * @author Marian Ziegler  <ziegler@edu-sharing.net>
14
 */
15
class AppAuthException extends Exception
16
{
17
    private const KNOWN_ERRORS = [
18
        "the timestamp sent by your client was too old. Please check the clocks of both servers or increase the value 'message_offset_ms'/'message_send_offset_ms' in the app properties file"
19
        => ['MESSAGE SEND TIMESTAMP TO OLD', 'MESSAGE SEND TIMESTAMP newer than MESSAGE ARRIVED TIMESTAMP'],
20
        "The ip your client is using for request is not known by the repository. Please add the ip into your 'host_aliases' app properties file"
21
        => ['INVALID_HOST']
22
    ];
23
 
24
    /**
25
     * AppAuthException constructor
26
     *
27
     * @param string $message
28
     */
29
    public function __construct(string $message = '') {
30
        parent::__construct($this->getExplanation($message));
31
    }
32
 
33
    /**
34
     * Function getExplanation
35
     *
36
     * @param string $message
37
     * @return string
38
     */
39
    private function getExplanation(string $message): string {
40
        foreach (static::KNOWN_ERRORS as $desc => $keys) {
41
            foreach ($keys as $k) {
42
                if (str_contains($message, $k))
43
                    return $desc . '(' . $message . ')';
44
            }
45
        }
46
        return $message;
47
    }
48
}