Cannot send Post Request Again after status 400 error even after correcting the request

1 answer

I have an Edit Product page. I am editing and product. If I Edit the product name with an already existing product of that name and submit a post request to Java Spring REST API using JWT. I have validation and it returns status 400 which is right.
But the problem is that without reloading the page when I correct the name field and resend it, Status 400 is shown again with the same error message. This is my Submit funtion:

 onSubmit() {     this.productSubmit = true;     if (       this.productFormGroup.valid &&       !this.isTableEmpty &&       this.isFormValid &&       !this.isCustomTableEmpty     ) {       this.isLoading = true;       this.product.name = this.f.name.value;       this.product.productCategory = this.f.category.value;       this.product.model = this.f.model.value;       this.product.barcode = this.f.barcode.value;       this.product.unit = this.f.unit.value;       this.product.manufacturer = this.f.manufacturer.value;       this.product.cost = this.f.cost.value;       this.product.minimumStockLevel = this.f.minStock.value;       this.product.description = this.f.description.value;       this.product.length=this.f.length.value;       this.product.width=this.f.width.value;       this.product.height=this.f.height.value;       this.product.weight=this.f.weight.value;        if (this.f.brand.value) {         this.product.brand = this.f.brand.value;       } else {         this.product.brand = null;       }       if (this.f.foreignName.value) {         this.product.foreign_name=this.f.foreignName.value;       } else {         let foreignName=this.f.name.value;         this.product.foreign_name=foreignName;       }       if (this.f.foreignSKU.value) {         this.product.foreign_sku=this.f.foreignSKU.value;       } else {         let foreignSKU=this.f.model.value;         this.product.foreign_sku=foreignSKU;       }       if (this.f.preferred_supplier.value) {         this.product.preferred_supplier=this.f.preferred_supplier.value;       } else {         this.product.preferred_supplier=null;       }       this.product.prices = this.myPriceLists;       let id = null;       if (this.activatedRoute.snapshot.params["id"]) {         id = this.activatedRoute.snapshot.params["id"];       } else {         this.router.navigate(["/loggedIn", "product", "list"]);       }       this.product.productCategory = this.selectedCategory;        this.formData.append(         "product",         new Blob(           [JSON.stringify(this.product, this.appService.jsonStringifier)],           { type: "application/json" }         )       );        this.images = this.images.concat(this.product.productImages);       for (let image of this.images) {         this.formData.append("images", image);       }       this.productService.updateProduct(this.formData, id).subscribe(         () => {           this.productService.resetProducts();           this.messageService.add({             severity: "info",             summary: "Success",             detail: "Product Successfully Edited"           });           this.router.navigate(["/loggedIn", "product", "list"]);         },         (errorResponse : HttpErrorResponse) => {           this.productErrors = this.appService.errorObjToMap(             errorResponse.error.errors           );           this.productSuccess = errorResponse.error.success;           this.isLoading = false;           this.messageService.add({             severity: "error",             summary: "Failure",             detail: "Product not edited."           });          console.log(errorResponse.error.errors[0].message);          },         () => {           this.successAlert = true;           this.isLoading = false;         }       );     }   }  

* This is what my REST Controller looks like for this request*

    @RequestMapping(value = "save/{id}", method = RequestMethod.POST)     public ResponseEntity addProduct(@PathVariable("id") Integer id, @Valid @RequestPart Product product, @RequestPart MultipartFile[] images, BindingResult bindingResult, HttpServletRequest request) throws IOException {         return saveProduct(id, product, images, bindingResult, request);     } 

Everything works fine except this. I hope you can understand the problem. If you have any question ask me or anything that I might have missed to give.

Received answer to this question:
The best answer according to the author of the question:

You should try re-setting the messageService object after the

console.log(errorResponse.error.errors[0].message); 

I am not familiar with Angular, but React and hence suggested an answer from that perspective.