After executing my code in TypeScript, I encountered an issue with the updateProduct method calling the API to update a product based on form values. The update functionality works fine, but afterwards, I am receiving the following error:
error:
SyntaxError: Unexpected token 'P', "Product Up"... is not valid JSON at JSON.parse
(<anonymous>) at XMLHttpRequest.onLoad (https://localhost:4200/vendor.js:36220:39) at
"Unexpected token 'P', \"Product Up\"... is not valid JSON"
stack:
"SyntaxError: Unexpected token 'P', \"Product Up\"... is not valid JSON\n at JSON.parse (<anonymous>)\n at XMLHttpRequest.onLoad (https://localhost:4200/vendor.js:36220:39)
This error is being caught in the TypeScript file where the updateProduct method is called.
this.shopService.updateProduct(this.productForm.value).subscribe(response => {
this.router.navigateByUrl('/admin');
}, error => {
console.log(error);
this.errors = error.errors;
});
I'm seeking assistance in understanding what is causing this specific error to occur.
Below is a snippet of code from the API:
var productMapped = _mapper.Map<ProductDto, Product>(product);
_productsRepo.Update(productMapped);
if(await _productsRepo.SaveAll())
{
return Ok("Product Updated with success");
}
return BadRequest("Could not update the product");