Angular - 303 response does not redirect

150 views Asked by At

I have a problem with redirect when getting a 303 response with Location URL from a backend API endpoint. The URL can point to any subpage on my page.

When the browser tries to redirect, I get an error:

error: SyntaxError: Unexpected token '<', ") at XMLHttpRequest.onLoad message: "Http failure during parsing for "

It seems that it treats the HTML response as JSON and tries to parse it, but why?

Thanks for your help.

I don't know what to do in this case.

1

There are 1 answers

2
Jacopo Sciampi On

Angular by default try to parse every response as JSON. You need to specify that is not. For example:

public getData(): Observable<string> {
  this._http.get<string>('url', {responseType: 'text'});
}