mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-20 13:26:08 +00:00
add http interceptor
This commit is contained in:
@@ -21,7 +21,14 @@ export class BackgroundService {
|
||||
private themeservice: ThemeService,
|
||||
private storageservice: StorageService,
|
||||
private http: HttpClient,
|
||||
) { }
|
||||
) {
|
||||
|
||||
window.addEventListener('focus', (event) => {
|
||||
if(this.status == 'offline') {
|
||||
this.tryToReachTheServer()
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
online() {
|
||||
if(this.status == 'online') {
|
||||
@@ -68,28 +75,36 @@ export class BackgroundService {
|
||||
return false
|
||||
}
|
||||
|
||||
const hasReachedTheServer = await this.tryToReachTheServer()
|
||||
|
||||
if(!hasReachedTheServer) {
|
||||
this.status = 'offline'
|
||||
document.body.style.setProperty(`--color`, "#ffb703");
|
||||
document.body.style.setProperty(`--color2`, "#ffb703");
|
||||
document.body.style.setProperty(`--color3`, "#ffb703");
|
||||
document.body.style.setProperty(`--color4`, "#ffb703");
|
||||
document.body.style.setProperty(`--color5`, "#ffb703");
|
||||
this.storageservice.store('networkCheckStore','offline');
|
||||
this.callBacks.forEach((e) => {
|
||||
if (e.type == 'Offline') {
|
||||
e.funx()
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
async tryToReachTheServer() {
|
||||
let opts = {
|
||||
headers: {},
|
||||
}
|
||||
|
||||
try {
|
||||
await this.http.post(environment.apiURL + "UserAuthentication/Login", '', opts).toPromise();
|
||||
return true
|
||||
} catch (error) {
|
||||
if(error.status != 400) {
|
||||
|
||||
this.status = 'offline'
|
||||
document.body.style.setProperty(`--color`, "#ffb703");
|
||||
document.body.style.setProperty(`--color2`, "#ffb703");
|
||||
document.body.style.setProperty(`--color3`, "#ffb703");
|
||||
document.body.style.setProperty(`--color4`, "#ffb703");
|
||||
document.body.style.setProperty(`--color5`, "#ffb703");
|
||||
this.storageservice.store('networkCheckStore','offline');
|
||||
this.callBacks.forEach((e) => {
|
||||
if (e.type == 'Offline') {
|
||||
e.funx()
|
||||
}
|
||||
})
|
||||
|
||||
return false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user