<commit_before>import { Injectable } from '@angular/core';
import { HttpEvent, HttpHandler, HttpInterceptor, HttpRequest } from '@angular/common/http';
import { Observable, throwError } from 'rxjs';
import { catchError } from 'rxjs/operators';
import { Router } from '@angular/router';
import { Store } from '@ngxs/store';
import { ShowToastr } from '../../shared/store/actions/toastr/toastr.actions';
import { ToastrType } from '../../shared/enum/toastr';
import { AuthState } from '../../features/auth/store/auth.state';
import { ClearCurrentUser } from '../../features/auth/store/auth.actions';
import { LSNAME } from '../settings/config';

@Injectable()
export class ErrorInterceptor implements HttpInterceptor {

    constructor(private router: Router,
                private store: Store) {
    }

    intercept(request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
        return next.handle(request).pipe(catchError(err => {

            const errorMsg = err.error && err.error.message ? err.error.message : `${LSNAME.defaultErrorMsg} ${LSNAME.emailError}`;

            if ([401].indexOf(err.status) !== -1) {
                if (this.store.selectSnapshot(AuthState.currentUser)) {
                    this.store.dispatch(new ClearCurrentUser(true));
                    this.store.dispatch(new ShowToastr(ToastrType.Error, 'Errore', errorMsg, null, null, true));
                }
            } else if ([403].indexOf(err.status) !== -1) {
                this.store.dispatch(new ShowToastr(ToastrType.Error, 'Errore', errorMsg, null, null));
            } else {
                if (request.url.indexOf('GetCompetenze') !== -1) {
                    this.store.dispatch(new ShowToastr(ToastrType.Error, 'Errore Competenze', 'Il servizio di reperimento competenze non è al momento raggiungibile, si prega di inserirle manualmente', null, null));
                } else {
                    if (errorMsg?.split(' ')[0] === '1*') {
                        this.store.dispatch(new ShowToastr(ToastrType.Error, 'Errore', errorMsg, null, null));
                    } else {
                        console.error('Errore applicativo del server');
                    }<commit_msg>Fix "error interceptor"<commit_after>import { Injectable } from '@angular/core';
import { HttpEvent, HttpHandler, HttpInterceptor, HttpRequest } from '@angular/common/http';
import { Observable, throwError } from 'rxjs';
import { catchError } from 'rxjs/operators';
import { Router } from '@angular/router';
import { Store } from '@ngxs/store';
import { ShowToastr } from '../../shared/store/actions/toastr/toastr.actions';
import { ToastrType } from '../../shared/enum/toastr';
import { AuthState } from '../../features/auth/store/auth.state';
import { ClearCurrentUser } from '../../features/auth/store/auth.actions';
import { LSNAME } from '../settings/config';

@Injectable()
export class ErrorInterceptor implements HttpInterceptor {

    constructor(private router: Router,
                private store: Store) {
    }

    intercept(request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
        return next.handle(request).pipe(catchError(err => {

            const errorMsg = err.error && err.error.message ? err.error.message : `${LSNAME.defaultErrorMsg} ${LSNAME.emailError}`;

            if ([401].indexOf(err.status) !== -1) {
                if (this.store.selectSnapshot(AuthState.currentUser)) {
                    this.store.dispatch(new ClearCurrentUser(true));
                    this.store.dispatch(new ShowToastr(ToastrType.Error, 'Errore', errorMsg, null, null, true));
                }
            } else if ([403].indexOf(err.status) !== -1) {
                this.store.dispatch(new ShowToastr(ToastrType.Error, 'Errore', errorMsg, null, null));
            } else {
                if (request.url.indexOf('GetCompetenze') !== -1) {
                    this.store.dispatch(new ShowToastr(ToastrType.Error, 'Errore Competenze', 'Il servizio di reperimento competenze non è al momento raggiungibile, si prega di inserirle manualmente', null, null));
                } else {
                    if (errorMsg?.split(' ')[0] === '1*') {
                        this.store.dispatch(new ShowToastr(ToastrType.Error, 'Errore', errorMsg.slice(3), null, null));
                    } else {
                        console.error('Errore applicativo del server');
                    }
{'fraction_non_alphanumeric': 0.1431147171512283, 'fraction_numerical': 0.005183682668469687, 'mean_word_length': 2.6199021207177813, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1697065', 'n_tokens_mistral': 1260, 'n_tokens_neox': 1248, 'n_words': 280}