chore: update Taiga UI and migrate some more forms (#2252)

This commit is contained in:
Alex Inkin
2023-04-21 21:45:49 +08:00
committed by Aiden McClelland
parent 6badf047c3
commit f83ae27352
7 changed files with 122 additions and 106 deletions

View File

@@ -40,6 +40,7 @@ export * from './pipes/unit-conversion/unit-conversion.pipe'
export * from './services/download-html.service'
export * from './services/emver.service'
export * from './services/error.service'
export * from './services/error-toast.service'
export * from './services/http.service'

View File

@@ -0,0 +1,43 @@
import { ErrorHandler, inject, Injectable } from '@angular/core'
import { TuiAlertService, TuiNotification } from '@taiga-ui/core'
import { HttpError } from '../classes/http-error'
// TODO: Enable this as ErrorHandler
@Injectable({
providedIn: 'root',
})
export class ErrorService extends ErrorHandler {
private readonly alerts = inject(TuiAlertService)
override handleError(error: HttpError | string, link?: string) {
console.error(error)
this.alerts
.open(getErrorMessage(error, link), {
label: 'Error',
autoClose: false,
status: TuiNotification.Error,
})
.subscribe()
}
}
function getErrorMessage(e: HttpError | string, link?: string): string {
let message = ''
if (typeof e === 'string') {
message = e
} else if (e.code === 0) {
message =
'Request Error. Your browser blocked the request. This is usually caused by a corrupt browser cache or an overly aggressive ad blocker. Please clear your browser cache and/or adjust your ad blocker and try again'
} else if (!e.message) {
message = 'Unknown Error'
link = 'https://docs.start9.com/latest/support/faq'
} else {
message = e.message
}
return link
? `${message}<br /><br /><a href=${link} target="_blank" rel="noreferrer">Get Help</a>`
: message
}