1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-29 18:22:41 +01:00

In Webhooks, give errors human-readable labels and show reminder text for "Silent Mode"

Summary:
Depends on D19928. See <https://discourse.phabricator-community.org/t/firehose-webhook-not-working-with-self-hosted-requestbin-instance/2240/>.

Currently, we report "hook" and "silent", which are raw internal codes.

Instead, report human-readable labels so the user gets a better hint about what's going on ("In Silent Mode").

Also, render a "hey, you're in silent mode so none of this will work" reminder banner in this UI.

Test Plan:
{F6074421}

Note:

  - New warning banner.
  - Table has more human-readable text ("In Silent Mode").

Reviewers: amckinley

Reviewed By: amckinley

Differential Revision: https://secure.phabricator.com/D19929
This commit is contained in:
epriestley 2018-12-22 04:20:35 -08:00
parent 3c65601285
commit 15df57f1c8
4 changed files with 88 additions and 9 deletions

View file

@ -50,6 +50,19 @@ final class HeraldWebhookViewController
->setLimit(20) ->setLimit(20)
->execute(); ->execute();
$warnings = array();
if (PhabricatorEnv::getEnvConfig('phabricator.silent')) {
$message = pht(
'Phabricator is currently configured in silent mode, so it will not '.
'publish webhooks. To adjust this setting, see '.
'@{config:phabricator.silent} in Config.');
$warnings[] = id(new PHUIInfoView())
->setTitle(pht('Silent Mode'))
->setSeverity(PHUIInfoView::SEVERITY_WARNING)
->appendChild(new PHUIRemarkupView($viewer, $message));
}
$requests_table = id(new HeraldWebhookRequestListView()) $requests_table = id(new HeraldWebhookRequestListView())
->setViewer($viewer) ->setViewer($viewer)
->setRequests($requests) ->setRequests($requests)

View file

@ -26,6 +26,15 @@ final class HeraldWebhookRequest
const RESULT_OKAY = 'okay'; const RESULT_OKAY = 'okay';
const RESULT_FAIL = 'fail'; const RESULT_FAIL = 'fail';
const ERRORTYPE_HOOK = 'hook';
const ERRORTYPE_HTTP = 'http';
const ERRORTYPE_TIMEOUT = 'timeout';
const ERROR_SILENT = 'silent';
const ERROR_DISABLED = 'disabled';
const ERROR_URI = 'uri';
const ERROR_OBJECT = 'object';
protected function getConfiguration() { protected function getConfiguration() {
return array( return array(
self::CONFIG_AUX_PHID => true, self::CONFIG_AUX_PHID => true,
@ -108,6 +117,28 @@ final class HeraldWebhookRequest
return $this->getProperty('errorCode'); return $this->getProperty('errorCode');
} }
public function getErrorTypeForDisplay() {
$map = array(
self::ERRORTYPE_HOOK => pht('Hook Error'),
self::ERRORTYPE_HTTP => pht('HTTP Error'),
self::ERRORTYPE_TIMEOUT => pht('Request Timeout'),
);
$type = $this->getErrorType();
return idx($map, $type, $type);
}
public function getErrorCodeForDisplay() {
$code = $this->getErrorCode();
if ($this->getErrorType() !== self::ERRORTYPE_HOOK) {
return $code;
}
$spec = $this->getHookErrorSpec($code);
return idx($spec, 'display', $code);
}
public function setTransactionPHIDs(array $phids) { public function setTransactionPHIDs(array $phids) {
return $this->setProperty('transactionPHIDs', $phids); return $this->setProperty('transactionPHIDs', $phids);
} }
@ -187,6 +218,28 @@ final class HeraldWebhookRequest
->setTooltip($tooltip); ->setTooltip($tooltip);
} }
private function getHookErrorSpec($code) {
$map = $this->getHookErrorMap();
return idx($map, $code, array());
}
private function getHookErrorMap() {
return array(
self::ERROR_SILENT => array(
'display' => pht('In Silent Mode'),
),
self::ERROR_DISABLED => array(
'display' => pht('Hook Disabled'),
),
self::ERROR_URI => array(
'display' => pht('Invalid URI'),
),
self::ERROR_OBJECT => array(
'display' => pht('Invalid Object'),
),
);
}
/* -( PhabricatorPolicyInterface )----------------------------------------- */ /* -( PhabricatorPolicyInterface )----------------------------------------- */

View file

@ -55,8 +55,8 @@ final class HeraldWebhookRequestListView
$request->getID(), $request->getID(),
$icon, $icon,
$handles[$request->getObjectPHID()]->renderLink(), $handles[$request->getObjectPHID()]->renderLink(),
$request->getErrorType(), $request->getErrorTypeForDisplay(),
$request->getErrorCode(), $request->getErrorCodeForDisplay(),
$last_request, $last_request,
); );
} }
@ -66,7 +66,7 @@ final class HeraldWebhookRequestListView
->setHeaders( ->setHeaders(
array( array(
pht('ID'), pht('ID'),
'', null,
pht('Object'), pht('Object'),
pht('Type'), pht('Type'),
pht('Code'), pht('Code'),

View file

@ -35,14 +35,20 @@ final class HeraldWebhookWorker
// If we're in silent mode, permanently fail the webhook request and then // If we're in silent mode, permanently fail the webhook request and then
// return to complete this task. // return to complete this task.
if (PhabricatorEnv::getEnvConfig('phabricator.silent')) { if (PhabricatorEnv::getEnvConfig('phabricator.silent')) {
$this->failRequest($request, 'hook', 'silent'); $this->failRequest(
$request,
HeraldWebhookRequest::ERRORTYPE_HOOK,
HeraldWebhookRequest::ERROR_SILENT);
return; return;
} }
$hook = $request->getWebhook(); $hook = $request->getWebhook();
if ($hook->isDisabled()) { if ($hook->isDisabled()) {
$this->failRequest($request, 'hook', 'disabled'); $this->failRequest(
$request,
HeraldWebhookRequest::ERRORTYPE_HOOK,
HeraldWebhookRequest::ERROR_DISABLED);
throw new PhabricatorWorkerPermanentFailureException( throw new PhabricatorWorkerPermanentFailureException(
pht( pht(
'Associated hook ("%s") for webhook request ("%s") is disabled.', 'Associated hook ("%s") for webhook request ("%s") is disabled.',
@ -59,7 +65,10 @@ final class HeraldWebhookWorker
'https', 'https',
)); ));
} catch (Exception $ex) { } catch (Exception $ex) {
$this->failRequest($request, 'hook', 'uri'); $this->failRequest(
$request,
HeraldWebhookRequest::ERRORTYPE_HOOK,
HeraldWebhookRequest::ERROR_URI);
throw new PhabricatorWorkerPermanentFailureException( throw new PhabricatorWorkerPermanentFailureException(
pht( pht(
'Associated hook ("%s") for webhook request ("%s") has invalid '. 'Associated hook ("%s") for webhook request ("%s") has invalid '.
@ -76,7 +85,11 @@ final class HeraldWebhookWorker
->withPHIDs(array($object_phid)) ->withPHIDs(array($object_phid))
->executeOne(); ->executeOne();
if (!$object) { if (!$object) {
$this->failRequest($request, 'hook', 'object'); $this->failRequest(
$request,
HeraldWebhookRequest::ERRORTYPE_HOOK,
HeraldWebhookRequest::ERROR_OBJECT);
throw new PhabricatorWorkerPermanentFailureException( throw new PhabricatorWorkerPermanentFailureException(
pht( pht(
'Unable to load object ("%s") for webhook request ("%s").', 'Unable to load object ("%s") for webhook request ("%s").',
@ -182,9 +195,9 @@ final class HeraldWebhookWorker
list($status) = $future->resolve(); list($status) = $future->resolve();
if ($status->isTimeout()) { if ($status->isTimeout()) {
$error_type = 'timeout'; $error_type = HeraldWebhookRequest::ERRORTYPE_TIMEOUT;
} else { } else {
$error_type = 'http'; $error_type = HeraldWebhookRequest::ERRORTYPE_HTTP;
} }
$error_code = $status->getStatusCode(); $error_code = $status->getStatusCode();