klmuralimohan
klmuralimohan

Reputation: 941

Angular 7 HTTP Post 500 Internal Server Error

For some reason, When submitting the form data first time it is working fine with Status Code: 200 OK. But second submission http post method returns **500 Internal Server Error** . When I reload the page same issue continue.

Here my try, expert advise please

TS service

 sendData(): Observable<Disciplines[]>  {
    return this.http.get<Disciplines[]>(this.configService.apiUrl + "data?gf=off");
  }

TS component

Form submission

onSubmit() {

this.requestBody = {
        name: { "en": this.form.value.discipline_en, "de": this.form.value.discipline_de },
        description: { "en": this.form.value.description_en, "de": this.form.value.description_de }
      }
    this.dataService.sendData(this.requestBody)
            .subscribe(data => {                  
              this.notificationService.showNotification("success", "", "Created successfully");

            });
}

Upvotes: 0

Views: 21618

Answers (2)

maury844
maury844

Reputation: 1250

As suggested by @Ntwobike, the issue is on your Server code, therefore the Internal Server error response.

There are a few reasons why the form submission is working the first time after a reload, maybe the form "inits" itself with a value, on some of the controls, and you are not properly restoring to "default" values after the first submission (This happened to me with dropdowns), then since your backend is not able to get all the information it needs it's throwing the error on some property.

Check the server logs, or if you have access to the server code, put some breakpoints on your service.

Upvotes: 0

Ntwobike
Ntwobike

Reputation: 2751

Internal server error is self explanatory. Check the logs in the server. You can see that its already reached the server with 200, while processing the request got an exception 500. Something wrong with your backend service.

Upvotes: 4

Related Questions