1
0
mirror of https://github.com/dwaxweiler/connector-mobilizon synced 2025-06-05 21:59:25 +02:00

fix showing group not found error in block

This commit is contained in:
Daniel Waxweiler 2025-05-23 21:21:04 +02:00
parent 3e2aac7657
commit 10f4f3eceb
4 changed files with 13 additions and 16 deletions

View File

@ -8,6 +8,7 @@
#### Deprecated #### Deprecated
#### Removed #### Removed
#### Fixed #### Fixed
- Show group not found error message in block
#### Security #### Security
- Escape translated strings to prevent HTML injections - Escape translated strings to prevent HTML injections

View File

@ -39,7 +39,14 @@ export default ({ attributes, setAttributes }) => {
} }
container.querySelector('a').href = showMoreUrl container.querySelector('a').href = showMoreUrl
await fetch(url) await fetch(url)
.then((response) => response.text()) .then(async (response) => {
if (!response.ok) {
// Reject if no 2xx response.
const data = await response.text()
return Promise.reject(data)
}
return response.text()
})
.then((data) => { .then((data) => {
const events = JSON.parse(data) const events = JSON.parse(data)
displayEvents({ displayEvents({
@ -50,7 +57,8 @@ export default ({ attributes, setAttributes }) => {
}) })
}) })
.catch((data) => { .catch((data) => {
displayErrorMessage({ data, container }) const parsedData = JSON.parse(data)
displayErrorMessage({ data: parsedData, container })
}) })
} }
}, 500) }, 500)

View File

@ -83,13 +83,7 @@ test('#displayErrorMessage general error message display', (t) => {
test('#displayErrorMessage group not found error message display', (t) => { test('#displayErrorMessage group not found error message display', (t) => {
const container = t.context.container const container = t.context.container
const data = { const data = {
response: { code: 'group_not_found',
errors: [
{
code: 'group_not_found',
},
],
},
} }
displayErrorMessage({ data, container }) displayErrorMessage({ data, container })
t.is(container.querySelector('.general-error').style.display, 'none') t.is(container.querySelector('.general-error').style.display, 'none')

View File

@ -72,13 +72,7 @@ export function displayEvents({ events, document, container, maxEventsCount }) {
export function displayErrorMessage({ data, container }) { export function displayErrorMessage({ data, container }) {
hideLoadingIndicator(container) hideLoadingIndicator(container)
if ( if (Object.hasOwn(data, 'code') && data.code === 'group_not_found') {
Object.prototype.hasOwnProperty.call(data, 'response') &&
Object.prototype.hasOwnProperty.call(data.response, 'errors') &&
data.response.errors.length > 0 &&
Object.prototype.hasOwnProperty.call(data.response.errors[0], 'code') &&
data.response.errors[0].code === 'group_not_found'
) {
const message = container.querySelector('.group-not-found') const message = container.querySelector('.group-not-found')
message.style.display = 'block' message.style.display = 'block'
} else { } else {