mirror of
https://github.com/Start9Labs/start-os.git
synced 2026-04-02 05:23:14 +00:00
chore: update Taiga UI and migrate some more forms (#2252)
This commit is contained in:
committed by
Aiden McClelland
parent
6badf047c3
commit
f83ae27352
@@ -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'
|
||||
|
||||
|
||||
43
frontend/projects/shared/src/services/error.service.ts
Normal file
43
frontend/projects/shared/src/services/error.service.ts
Normal 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
|
||||
}
|
||||
Reference in New Issue
Block a user