Как вывести определенную часть из ошибки

У меня есть ошибка, она выводится вся, а мне хотелось бы вывести только Invalid password

Store.Shared.Common.Exceptions.ServerException: Invalid password
   at Store.BusinessLogicLayer.Services.AccountService.SignInAsync(LoginModel model) in D:\Store\Store.BusinessLogicLayer\Services\AccountService.cs:line 137
   at Store.PresentationLayer.Controllers.AccountController.SignInAsync(LoginModel model)

Я пытаюсь конвертировать так

 let error: string[] = JSON.parse(JSON.stringify(errorMessage.error));

Ответы (1 шт):

Автор решения: Alexander Chernin

С типом исключения:

let errorString = `Store.Shared.Common.Exceptions.ServerException: Invalid password
   at Store.BusinessLogicLayer.Services.AccountService.SignInAsync(LoginModel model) in D:\Store\Store.BusinessLogicLayer\Services\AccountService.cs:line 137
   at Store.PresentationLayer.Controllers.AccountController.SignInAsync(LoginModel model)`;

let end = errorString.indexOf("at");
let message = errorString.slice(0, end).trim();
console.log(message); // "Store.Shared.Common.Exceptions.ServerException: Invalid password"

Если только сообщение без типа исключения, то так:

let errorString = `Store.Shared.Common.Exceptions.ServerException: Invalid password
   at Store.BusinessLogicLayer.Services.AccountService.SignInAsync(LoginModel model) in D:\Store\Store.BusinessLogicLayer\Services\AccountService.cs:line 137
   at Store.PresentationLayer.Controllers.AccountController.SignInAsync(LoginModel model)`;

let start = errorString.indexOf(":");
let end = errorString.indexOf("at");
let message = errorString.slice(start +1, end).trim();
console.log(message); // "Invalid password"
→ Ссылка