summaryrefslogtreecommitdiff
path: root/bin/wiki/vendor/addwiki/mediawiki-api-base/src/UsageException.php
blob: 77148f1b4c4f44a698089cfb6a9ffba859ada744 (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
70
71
72
73
74
75
<?php

namespace Mediawiki\Api;

use Exception;

/**
 * Class representing a Mediawiki Api UsageException
 *
 * @since 0.1
 *
 * @author Addshore
 */
class UsageException extends Exception {

	/**
	 * @var string
	 */
	private $apiCode;

	/**
	 * @var array
	 */
	private $result;

	/**
	 * @var string
	 */
	private $rawMessage;

	/**
	 * @since 0.1
	 *
	 * @param string $apiCode The API error code.
	 * @param string $message The API error message.
	 * @param array $result the result the exception was generated from
	 */
	public function __construct( $apiCode = '', $message = '', $result = [] ) {
		$this->apiCode = $apiCode;
		$this->result = $result;
		$this->rawMessage = $message;
		$message = 'Code: ' . $apiCode . PHP_EOL .
			'Message: ' . $message . PHP_EOL .
			'Result: ' . json_encode( $result );
		parent::__construct( $message, 0, null );
	}

	/**
	 * @since 0.1
	 *
	 * @return string
	 */
	public function getApiCode() {
		return $this->apiCode;
	}

	/**
	 * @since 0.3
	 *
	 * @return array
	 */
	public function getApiResult() {
		return $this->result;
	}

	/**
	 * @since 2.3.0
	 *
	 * @return string
	 */
	public function getRawMessage() {
		return $this->rawMessage;
	}

}