#http error

14 messages · Page 1 of 1 (latest)

wheat lance
#

the back generates an error 400 which is normal.
i want to intercept the error on angular to process it.

  createRecord(): Observable<any> {
    const headers = new HttpHeaders().set("keyidentity", keyidentity);
    return this._httpClient.post(`${requestUrl}`, equipe, { headers });
  }

(1)

          this.createRecord()          
          .pipe(catchError((error: any, caught: Observable<any>): Observable<any> => {
            console.error(error);  // ???
            return of();
          }))
          .subscribe(() => {
   
          });

(2)

          this.createRecord(requestUrl, delegationPost, this._authentificationService.getConnectedIdentity()).subscribe({
            next: () => {

             },
             error: (error: any) => {
                console.log(error);   // ??
             }
          });

(1) and (2)

TypeError: You provided 'null' where a stream was expected. You can provide an Observable, Promise, ReadableStream, Array, AsyncIterable, or Iterable.
    at createInvalidObservableTypeError (throwUnobservableError.js:2:12)
    at innerFrom (innerFrom.js:37:43)
    at catchError.js:10:38

I don't understand this error, how can I resolve it? I'd like to get the content of the error in the reply to the request I have :

{
    "entityName": "La délégation existe déjà",
    "errorKey": "La délégation existe déjà",
    "type": "/problem-with-message",
    "title": "La délégation existe déjà",
    "status": 400,
    "message": "error.La délégation existe déjà",
    "params": "La délégation existe déjà"
}

console.log(error); // doesn't display the content of the answer?

woeful relic
#

Do you want the response JSON or just to know that it failed?

#

I mean response object

wheat lance
#

yes

#

response object

woeful relic
#

Then you can add { observe: 'response' } to the http client call

wheat lance
#

i don't understand

woeful relic
#
httpClient.post(x, y, { headers, observe: 'response' })
#

That'll give you the response

wheat lance
#

ok i try

#

it doesn't work .it's been running in production for 4 months and it worked fine with the code I put above. today it doesn't work anymore.

#

do you know why? an idea ?

wheat lance
#

how to resolve it ?

wheat lance
#

What does this error mean?

TypeError: You provided 'null' where a stream was expected. You can provide an Observable, Promise, ReadableStream, Array, AsyncIterable, or Iterable.
    at 

can interceptors block error?can interceptors block error?

@Injectable()
export class TokenInterceptor implements HttpInterceptor {
  constructor() { }

  intercept(request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {


    const authReq = request.clone({
      setHeaders: {
      'Authorization': 'Bearer '+localStorage.getItem("idToken"),
        'Access-Control-Allow-Origin': '*'
      },
      withCredentials: true,
    })

    return next.handle(authReq);
  }
}