APIv4 - Add Address::getCoordinates action
[civicrm-core.git] / CRM / Core / Page / FakeError.php
CommitLineData
809f84c7
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
5 | |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
10 */
11
12/**
13 * The "civicrm/dev/fake-error" page is a mock to facilitate E2E testing of the error-reporting mechanism.
14 * Use this page to provoke common/representative errors.
15 *
16 * Of course, we don't want to permit arbitrary users to provoke arbitrary errors -- that could
17 * lead to noisy/confusing logs.
18 *
19 * This has two main modes:
20 *
21 * - If you give no parameters (or unsigned parameters), it simply says "Hello world".
22 * - If you give an authentic JWT with the claim `civi.fake-error`, then it will report
23 * one of the pre-canned error messages.
24 */
25class CRM_Core_Page_FakeError extends CRM_Core_Page {
26
27 public function run() {
28 try {
29 /** @var \Civi\Crypto\CryptoJwt $jwt */
30 $jwt = Civi::service('crypto.jwt');
31 $claims = $jwt->decode(CRM_Utils_Request::retrieve('token', 'String'));
32 }
33 catch (\Exception $e) {
34 $claims = [];
35 }
36
37 if (empty($claims['civi.fake-error'])) {
38 echo 'Hello world';
39 return;
40 }
41
42 switch ($claims['civi.fake-error']) {
43 case 'exception':
44 throw new \CRM_Core_Exception("This is a fake problem (exception).");
45
46 case 'fatal':
47 CRM_Core_Error::fatal('This is a fake problem (fatal).');
48 break;
49
50 case 'permission':
51 CRM_Utils_System::permissionDenied();
52 break;
53
54 default:
55 return 'Unrecognized error type.';
56 }
57 }
58
59}