HttpErrorResponse angular 7

Discussão em 'Angular' iniciado por kasko, Novembro 9, 2024.

  1. kasko

    kasko Guest

    I am working on an angular 7 application but I encounter a problem with a get request.

    Here is the error :


    HttpErrorResponse {headers: HttpHeaders, status: 302, statusText: "OK", url: "http://localhost:9090/things/", ok: false, …}
    error: Array(2)
    0: {thingId: 7, thingName: "thingName 1"}
    1: {thingId: 9, thingName: "thingName 2"}
    length: 2
    __proto__: Array(0)
    headers: HttpHeaders {normalizedNames: Map(0), lazyUpdate: null, lazyInit: ƒ}
    message: "Http failure response for http://localhost:9090/things/: 302 OK"
    name: "HttpErrorResponse"
    ok: false
    status: 302
    statusText: "OK"
    url: "http://localhost:9090/things/"
    __proto__: HttpResponseBase

    here is my RoleService.ts :

    @Injectable({ providedIn: 'root' })
    export default class RoleService {

    constructor(private http: HttpClient) { }

    getAllRoles(): Observable<Array<Role>> {
    return this.http.get<Array<Role>>(RoleUrls.allRoles).pipe(
    catchError(this.handleError('getRoles', []))
    )
    }

    handleError<T> (operation = 'operation', result?: T) {
    return (error: any): Observable<T> => {
    console.error(error); // log to console
    return of(result as T);
    };
    }
    }


    Here is the component.ts

    @Component({
    selector: 'app-role',
    templateUrl: './role.component.html',
    styleUrls: ['./role.component.css']
    })
    export class RoleComponent implements OnInit {

    roles: Array<Role>;
    constructor(private roleService: RoleService) { }

    ngOnInit() {
    this.getRoles();
    }

    getRoles(): void {
    this.roleService.getAllRoles().subscribe(roles => {
    this.roles = roles
    }, error => {
    console.log(error); // The error is here
    })
    }
    }


    I do not understand where this error comes from while the server sends me the requested data.

    Thank you in advance !!!

    Continue reading...

Compartilhe esta Página