|
63 | 63 |
|
64 | 64 | tags.push(...tagsToAdd); |
65 | 65 |
|
66 | | - await apiFetch(`/v2/blog/${uuid}/posts/${postId}`, { |
67 | | - method: 'PUT', |
68 | | - body: { |
69 | | - content, |
70 | | - date, |
71 | | - hide_trail: hideTrail, |
72 | | - placement_id: placementId, |
73 | | - slug, |
74 | | - tags: tags.join(',') |
| 66 | + try { |
| 67 | + const { response: { displayText } } = await apiFetch(`/v2/blog/${uuid}/posts/${postId}`, { |
| 68 | + method: 'PUT', |
| 69 | + body: { |
| 70 | + content, |
| 71 | + date, |
| 72 | + hide_trail: hideTrail, |
| 73 | + placement_id: placementId, |
| 74 | + slug, |
| 75 | + tags: tags.join(',') |
| 76 | + } |
| 77 | + }); |
| 78 | + |
| 79 | + browser.runtime.sendMessage({ |
| 80 | + command: 'notifications:create', |
| 81 | + arguments: { |
| 82 | + options: { type: 'basic', title: 'XKit', message: displayText } |
| 83 | + } |
| 84 | + }); |
| 85 | + |
| 86 | + const tagsElement = Object.assign(document.createElement('div'), { className: tagsClass }); |
| 87 | + |
| 88 | + const innerTagsDiv = document.createElement('div'); |
| 89 | + tagsElement.appendChild(innerTagsDiv); |
| 90 | + |
| 91 | + for (const tag of tags) { |
| 92 | + innerTagsDiv.appendChild(Object.assign(document.createElement('a'), { |
| 93 | + textContent: `#${tag.trim()}`, |
| 94 | + href: `/tagged/${encodeURIComponent(tag)}`, |
| 95 | + target: '_blank' |
| 96 | + })); |
75 | 97 | } |
76 | | - }); |
77 | | - |
78 | | - const tagsElement = Object.assign(document.createElement('div'), { className: tagsClass }); |
79 | 98 |
|
80 | | - const innerTagsDiv = document.createElement('div'); |
81 | | - tagsElement.appendChild(innerTagsDiv); |
82 | | - |
83 | | - for (const tag of tags) { |
84 | | - innerTagsDiv.appendChild(Object.assign(document.createElement('a'), { |
85 | | - textContent: `#${tag.trim()}`, |
86 | | - href: `/tagged/${encodeURIComponent(tag)}`, |
87 | | - target: '_blank' |
88 | | - })); |
| 99 | + postElement.querySelector('footer').parentNode.prepend(tagsElement); |
| 100 | + } catch ({ body }) { |
| 101 | + browser.runtime.sendMessage({ |
| 102 | + command: 'notifications:create', |
| 103 | + arguments: { |
| 104 | + options: { type: 'basic', title: 'XKit', message: body.errors[0].detail } |
| 105 | + } |
| 106 | + }); |
89 | 107 | } |
90 | | - |
91 | | - postElement.querySelector('footer').parentNode.prepend(tagsElement); |
92 | 108 | }; |
93 | 109 |
|
94 | 110 | const processPosts = async function () { |
|
0 commit comments