'SyntaxError: Unexpected token S in JSON at position 0 at JSON.parse

I'm trying to remove message notification. but this error appear "SyntaxError: Unexpected token S in JSON at position 0 at JSON.parse" , is there any relation with the type defined in the headers? How can i resolve this error?

Front-End Angular 12

public removeNotificationForUser(onlineUserModel: OnlineUserModel) {
    let targetUsername = onlineUserModel.userName;
    const url_ = `${this.baseUrlRemoveNotifications}?targetUsername=${targetUsername}`;
    const url = this.baseUrlRemoveNotifications + "/" + targetUsername;

    const body = {};
    const options = {
      headers: new HttpHeaders({
        "Content-Type": "application/json",
        "X-XSRF-TOKEN": this.cookieService.get("XSRF-TOKEN"),
      }),
    };
    return this.http.patch<any>(url_, body, options).subscribe(
      (val) => {
        console.log("PATCH call successful value returned in body", val);
      },
      (response) => {
        console.log("PATCH call in error", response);
      },
      () => {
        console.log("The PATCH observable is now completed.");
      }
    );
  }

Back-End Asp.net Core

[HttpPatch("[action]/{targetUsername}")]
        [Route("removeNotifications")]
        public async Task<IActionResult> RemoveNotifications( [FromQuery] string targetUsername)
        {
            try
            {

                var sender = await _userManager.FindByNameAsync(targetUsername);
                var reciever = await _userManager.FindByNameAsync(User.Identity.Name);

                // Find The Connection
                var RecieverResetNotification= _userInfoInMemory.GetUserInfo(User.Identity.Name);
                var SenderResetNotification = _userInfoInMemory.GetUserInfo(targetUsername);

                var notificationToBeRemoved = _context.Notifications.Where(N => ((N.ReceiverId == reciever.Id) && (N.SenderId == sender.Id) && (N.IsSeen == false))).ToList();

                //Send My reset notification to the the others sessions :

                var mySessions = _context.Connections.Where(C => ((C.ConnectionID != RecieverResetNotification.ConnectionID) && (C.Username == reciever.UserName) && (C.Connected == true))).Select(MyCID => MyCID.ConnectionID).ToList();

                if (mySessions != null)
                {
                    await _hubContext.Clients.Clients(mySessions).SendAsync("MyResetNotification", RecieverResetNotification);
                }
                //Test if notificationToBeRemoved
                if (notificationToBeRemoved != null)
                { 
                notificationToBeRemoved.ForEach(NR => NR.IsSeen = true);
                _context.SaveChanges();
                }
                // My Methode to update Notification Table => change Iseen column to true //
                return Ok("Success");
            }
            catch (Exception ex)
            {
                Log.Error("An error occurred while seeding the database  {Error} {StackTrace} {InnerException} {Source}",
                   ex.Message, ex.StackTrace, ex.InnerException, ex.Source);
            }
            return BadRequest("Failed");
            
        }



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source