notificatiosn error handling
This commit is contained in:
parent
1007015582
commit
f8a8951233
2 changed files with 14 additions and 17 deletions
|
|
@ -13,9 +13,10 @@ function humanizeErrors(errors) {
|
||||||
export function StatusCodeError(statusCode, body, options, response) {
|
export function StatusCodeError(statusCode, body, options, response) {
|
||||||
this.name = 'StatusCodeError'
|
this.name = 'StatusCodeError'
|
||||||
this.statusCode = statusCode
|
this.statusCode = statusCode
|
||||||
|
this.statusText = body.error.error || body.error
|
||||||
this.details = JSON && JSON.stringify ? JSON.stringify(body) : body
|
this.details = JSON && JSON.stringify ? JSON.stringify(body) : body
|
||||||
this.errorData = body.error
|
this.errorData = body.error
|
||||||
this.message = statusCode + ' - ' + body.error.error || body.error
|
this.message = statusCode + ' - ' + statusText
|
||||||
this.error = body // legacy attribute
|
this.error = body // legacy attribute
|
||||||
this.options = options
|
this.options = options
|
||||||
this.response = response
|
this.response = response
|
||||||
|
|
|
||||||
|
|
@ -83,27 +83,23 @@ const fetchAndUpdate = ({ store, credentials, older = false, sinceId }) => {
|
||||||
const fetchNotifications = ({ store, args, older }) => {
|
const fetchNotifications = ({ store, args, older }) => {
|
||||||
return fetchTimeline(args)
|
return fetchTimeline(args)
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
if (response.errors) {
|
|
||||||
if (
|
|
||||||
response.status === 400 &&
|
|
||||||
response.statusText.includes('Invalid value for enum')
|
|
||||||
) {
|
|
||||||
response.statusText
|
|
||||||
.matchAll(/(\w+) - Invalid value for enum./g)
|
|
||||||
.toArray()
|
|
||||||
.map((x) => x[1])
|
|
||||||
.forEach((x) => mastoApiNotificationTypes.delete(x))
|
|
||||||
return fetchNotifications({ store, args, older })
|
|
||||||
} else {
|
|
||||||
throw new Error(`${response.status} ${response.statusText}`)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const notifications = response.data
|
const notifications = response.data
|
||||||
update({ store, notifications, older })
|
update({ store, notifications, older })
|
||||||
return notifications
|
return notifications
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
|
if (
|
||||||
|
error.statusCode === 400 &&
|
||||||
|
error.statusText.includes('Invalid value for enum')
|
||||||
|
) {
|
||||||
|
error.statusText
|
||||||
|
.matchAll(/(\w+) - Invalid value for enum./g)
|
||||||
|
.toArray()
|
||||||
|
.map((x) => x[1])
|
||||||
|
.forEach((x) => mastoApiNotificationTypes.delete(x))
|
||||||
|
return fetchNotifications({ store, args, older })
|
||||||
|
}
|
||||||
|
|
||||||
useInterfaceStore().pushGlobalNotice({
|
useInterfaceStore().pushGlobalNotice({
|
||||||
level: 'error',
|
level: 'error',
|
||||||
messageKey: 'notifications.error',
|
messageKey: 'notifications.error',
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue