Skip to content

Commit c6c1e34

Browse files
committed
feat: improve webhook request/response body preview
1 parent 8e5927b commit c6c1e34

3 files changed

Lines changed: 23 additions & 7 deletions

File tree

src/Umbraco.Web.UI.Client/src/views/webhooks/logs.html

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
<thead>
44
<tr>
55
<th></th>
6-
<th><localize key="webhooks_webhookKey">Webhook key</localize></th>
76
<th><localize key="general_date">Date</localize></th>
87
<th><localize key="webhooks_url">Url</localize></th>
98
<th><localize key="webhooks_event">Event</localize></th>
@@ -20,7 +19,6 @@
2019
</umb-checkmark>
2120
<umb-icon icon="icon-wrong" class="umb-checkmark umb-checkmark--m" style="cursor: default;" ng-if="!vm.isChecked(log)"></umb-icon>
2221
</td>
23-
<td>{{ log.webhookKey }}</td>
2422
<td>{{ log.formattedLogDate }}</td>
2523
<td>{{ log.url }}</td>
2624
<td>{{ log.eventAlias }}</td>

src/Umbraco.Web.UI.Client/src/views/webhooks/overlays/details.controller.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,15 @@
55

66
vm.close = close;
77
vm.formatData = formatData;
8+
vm.detectLanguage = detectLanguage;
89

910
function formatData(data) {
1011

1112
let obj = data;
1213

1314
if (data.detectIsJson()) {
1415
try {
15-
obj = Utilities.fromJson(data)
16+
obj = JSON.stringify(Utilities.fromJson(data), null, 2);
1617
} catch (err) {
1718
obj = data;
1819
}
@@ -21,6 +22,21 @@
2122
return obj;
2223
}
2324

25+
function detectLanguage(headers, defaultLanguage) {
26+
const matches = headers.match(/^Content-Type:\s*(?<type>[a-z\/+.-]+)(\;?.*?)$/mi)
27+
if (matches) {
28+
const contentType = matches.groups["type"];
29+
if (contentType === "application/json")
30+
return "JSON";
31+
if (contentType === "text/html")
32+
return "HTML";
33+
if (contentType === "application/xml" || contentType === "text/xml")
34+
return "XML";
35+
}
36+
37+
return defaultLanguage || "TEXT";
38+
}
39+
2440
function close() {
2541
if ($scope.model && $scope.model.close) {
2642
$scope.model.close();

src/Umbraco.Web.UI.Client/src/views/webhooks/overlays/details.html

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@
4545
<div>{{model.log.retryCount}}</div>
4646
</umb-control-group>
4747

48+
<umb-control-group label="Webhook key">
49+
<div>{{model.log.webhookKey}}</div>
50+
</umb-control-group>
51+
4852
</umb-box-content>
4953

5054
</umb-box>
@@ -53,16 +57,14 @@
5357
<umb-box-header title="Request"></umb-box-header>
5458
<umb-box-content class="block-form">
5559
<pre class="code">{{model.log.requestHeaders}}</pre>
56-
<umb-code-snippet language="'JSON'" wrap="true">{{vm.formatData(model.log.requestBody) | json}}
57-
</umb-code-snippet>
60+
<umb-code-snippet language="vm.detectLanguage(model.log.requestHeaders, 'JSON')" wrap="true">{{vm.formatData(model.log.requestBody)}}</umb-code-snippet>
5861
</umb-box-content>
5962
</umb-box>
6063
<umb-box>
6164
<umb-box-header title="Response"></umb-box-header>
6265
<umb-box-content class="block-form">
6366
<pre class="code">{{model.log.responseHeaders}}</pre>
64-
<umb-code-snippet language="'TEXT'" wrap="true">{{vm.formatData(model.log.responseBody) | json}}
65-
</umb-code-snippet>
67+
<umb-code-snippet language="vm.detectLanguage(model.log.responseHeaders)" wrap="true">{{vm.formatData(model.log.responseBody)}}</umb-code-snippet>
6668
</umb-box-content>
6769
</umb-box>
6870
<div ng-if="model.log.exceptionOccured">

0 commit comments

Comments
 (0)