# Struggling with HTTP Module in Angular

**URL:** <https://forum.codewithmosh.com/t/struggling-with-http-module-in-angular/1538>\
**Category:** Angular\
**Created:** [December 29, 2020, 9:18pm UTC](https://forum.codewithmosh.com/t/struggling-with-http-module-in-angular/1538 "2020-12-29T21:18:41Z")\
**Posts on this page:** 1\
**Showing post:** 11

<div class="post-metadata">

**Author:** ![pesz](https://avatars.discourse-cdn.com/v4/letter/p/51bf81/32.png) [@pesz](https://forum.codewithmosh.com/u/pesz)\
**Post date:** [November 7, 2023, 7:58pm UTC](https://forum.codewithmosh.com/t/struggling-with-http-module-in-angular/1538/11 "2023-11-07T19:58:06Z")

</div>

Very useful post. Thank you.

Today the url works properly with https only and createPost method seems to be fine this way:

```auto
  createPost(input: HTMLInputElement) { 
    input.value = "";

    this.http.post(this.url, post)
      .subscribe(response => {
        post['id'] = response?.['id'];
        this.posts.splice(0, 0, post); 
      });
  }

```

After error handling:

```auto
  createPost(input: HTMLInputElement) {
    let post: any = { title: input.value };
    input.value = '';                   

    this.service.createPost(post)
      .subscribe({
        next: (response) => {
          post['id'] = response?.['id'];
          this.posts.splice(0, 0, post);
        },
        error: (error: Response) => {
          if (error.status === 400) {
            //this.form.setErrors(error);
          }
          else {
            alert('An unexpected error occured.');
            console.log(error);
          }
        }
      });
  }

```

Actually this post is pretty useful about the error handling section:

> [@Throwing Application-specific Errors .catch](https://forum.codewithmosh.com/t/throwing-application-specific-errors-catch/505/7):
>
> throwError method signature taking an error value is being removed in version 8. I’m currently on rxjs version 7.5.7. Angular 15. Also be sure you import your custom NotFoundError class, rather than from rxjs (same thing in the component), which auto import will do. Below is the implementation I used: import { Observable, throwError } from 'rxjs'; import { catchError } from 'rxjs/operators'; import { AppError } from '../common/app-error'; import { NotFoundError } from …

---

_[View the full topic](https://forum.codewithmosh.com/t/struggling-with-http-module-in-angular/1538)._
