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:
parent
3e2aac7657
commit
10f4f3eceb
@ -8,6 +8,7 @@
|
||||
#### Deprecated
|
||||
#### Removed
|
||||
#### Fixed
|
||||
- Show group not found error message in block
|
||||
#### Security
|
||||
- Escape translated strings to prevent HTML injections
|
||||
|
||||
|
@ -39,7 +39,14 @@ export default ({ attributes, setAttributes }) => {
|
||||
}
|
||||
container.querySelector('a').href = showMoreUrl
|
||||
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) => {
|
||||
const events = JSON.parse(data)
|
||||
displayEvents({
|
||||
@ -50,7 +57,8 @@ export default ({ attributes, setAttributes }) => {
|
||||
})
|
||||
})
|
||||
.catch((data) => {
|
||||
displayErrorMessage({ data, container })
|
||||
const parsedData = JSON.parse(data)
|
||||
displayErrorMessage({ data: parsedData, container })
|
||||
})
|
||||
}
|
||||
}, 500)
|
||||
|
@ -83,13 +83,7 @@ test('#displayErrorMessage general error message display', (t) => {
|
||||
test('#displayErrorMessage group not found error message display', (t) => {
|
||||
const container = t.context.container
|
||||
const data = {
|
||||
response: {
|
||||
errors: [
|
||||
{
|
||||
code: 'group_not_found',
|
||||
},
|
||||
],
|
||||
},
|
||||
}
|
||||
displayErrorMessage({ data, container })
|
||||
t.is(container.querySelector('.general-error').style.display, 'none')
|
||||
|
@ -72,13 +72,7 @@ export function displayEvents({ events, document, container, maxEventsCount }) {
|
||||
|
||||
export function displayErrorMessage({ data, container }) {
|
||||
hideLoadingIndicator(container)
|
||||
if (
|
||||
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'
|
||||
) {
|
||||
if (Object.hasOwn(data, 'code') && data.code === 'group_not_found') {
|
||||
const message = container.querySelector('.group-not-found')
|
||||
message.style.display = 'block'
|
||||
} else {
|
||||
|
Loading…
x
Reference in New Issue
Block a user