0

I am currently developing an angular app with a java backend. So far everything seemed to work, but now I run into an unexplainable issue. There is one GET request that does not work. Everything else works. But funny enough, it only does not work in Firefox.

When I print out the err of the observable this shows in the console:

{
  "headers": {
    "normalizedNames": {},
    "lazyUpdate": null,
    "headers": {}
  },
  "status": 0,
  "statusText": "Unknown Error",
  "url": null,
  "ok": false,
  "name": "HttpErrorResponse",
  "message": "Http failure response for (unknown url): 0 Unknown Error",
  "error": {
    "isTrusted": true
  }
}

When I look in the network tab, the request is not executed. Not even an preflight OPTIONS request.

I red several hints, that i will be a CORS issue. But i believe that's not the case here. My CORS headers are setup properly:

Access-Control-Allow-Headers: X-Requested-With, Content-Type, Authorization
Access-Control-Allow-Methods: GET, POST, DELETE, PUT, OPTIONS, HEAD
Access-Control-Allow-Origin: *
Content-Type: application/json

(usually I would set a more specific domain list for the CORS headers, but I set it set it to '*' just to be sure)

The request that does not work is on the resource /ads/:id. The request on /ads and all other requests work perfectly fine. All resources are realized with Jersey. And the request in question is not subject to any authentication or authorization.

To recap: Only one request only in Firefox does not work. If I go tho the URL directly (not via angular), everything works fine.

I am a little desperate here. Any help is appreciated.

For Clarification:

  • there is no error or something else in the developer console (neither in firefox nor chrome)
  • there is no request going out the browser in the network tab
  • there is no request coming in on the server side
  • error above is from console.log(err)
  • angular v5.2.9 and HttpClient are used

Narrowing down the Problem

My complete url is http://localhost:8080/api/v1/ads/1. And guess what the problem is the /ads part. I have absolutely no clue what exactly the causes this. I tried several other URLs like /ad /adsf /adsa etc. and all of them worked.

I also narrowed down the Angular to this:

import { Component, OnInit } from '@angular/core';
import { AdService } from '@app/shared/services/ad/ad.service';
import { HttpClient } from '@angular/common/http';

class Ad {
  id: number;
  title: string;
}

@Component({
  selector: 'fwas-ad-detail',
  template: `
  <div *ngIf="isError">
    <h1>Error</h1>
  </div>
  <div *ngIf="!isError">
    <h1>{{ad?.title}}</h1>
  </div>
  `
})
export class AdDetailComponent implements OnInit {

  url = 'http://localhost:8080/api/v1/ads';
  ad: Ad;
  isError = false;

  constructor(private http: HttpClient) { }

  ngOnInit() {
    const queryUrl = this.url + '/' + '1';
    this.http.get<Ad>(queryUrl).subscribe(
      data => { this.ad = data; },
      err => { this.isError = true; }
    );
  }
}

I also tried it with json server which worked fine.

So the problem only exists with the following:

  • angular 5 code above
  • Firefox 59.0.3 (64-bit)
  • Jersey2/Jackson2 API
  • And /ads in the URL, but not as last part (http://localhost:8080/api/v1/ads had always worked)

I have found a workaround for me (not using ads in the url) but if someone is bored and wants to figure this out, I would love to know what exactly is the reason for this mystery.

Mrvonwyl
  • 347
  • 2
  • 15
  • I already had a case where using `*` for `Allow-Origin` didn't work because not supported (allowed?) by the backend solution i used (it was Node IIRC), if you switch back to a declared origin, does it change anything? – Kaddath May 03 '18 at 13:11
  • Don't you have any other error in the browser's debugger (network tab/console)? What are the response body and header for that particular request? – David May 03 '18 at 13:12
  • Possible duplicate of https://stackoverflow.com/questions/47180634/i-get-http-failure-response-for-unknown-url-0-unknown-error-instead-of-actu – Leon May 03 '18 at 14:42
  • @David I do not have any response header or body, since there is no request sent in Firefox. I could post those of chrome, but there the request works perfectly fine, without any issue. – Mrvonwyl May 03 '18 at 16:13
  • In my case it was uBlock. I had a similar situation, but when I turned it off, it started working on Firefox too. – konkit Jul 17 '19 at 13:21
  • that might indeed be the case. I use AdBlock Plus in Firefox and none in Chrome or other browsers. I am not working on that project anymore though, but I might have a chance to revalidate it at some point. – Mrvonwyl Jul 18 '19 at 14:31

0 Answers0