ABP Framework version: v7.4.4 UI Type: Angular Database System: EF Core (SQL Server)
I have controller which is calling the service
public class ContactInformationsAppService : ApplicationService, IContactInformationsAppService
{
[Authorize(ClientsPermissions.ContactInformations.Create)]
public virtual async Task<ContactInformationDto> CreateAsync(ContactInformationCreateDto input)
{
if (await _contactInformationManager.checkContactExist(input.Email))
{
throw new UserFriendlyException("email {0} already exists", input.Email);
}
var contactInformation = await _contactInformationManager.CreateAsync(
input.ClientInfomationIds, input.ContactTypeId, input.ProvinceTypeId, input.FirstName, input.LastName, input.PhoneNumber, input.PreferredContactWay, input.IsIndemnitor, input.Percentage, input.CellNumber, input.FaxNumber, input.Email, input.Notes, input.MailingAddress, input.City, input.PostalCode, input.BusinessAddress, input.Website, input.Company, input.Description, input.ContactCode, input.AlternateEmail
);
return ObjectMapper.Map<ContactInformation, ContactInformationDto>(contactInformation);
}
}
// controller method
public class ContactInformationController : AbpController, IContactInformationsAppService
{ private readonly IContactInformationsAppService _contactInformationsAppService;
[HttpPost]
public virtual Task<ContactInformationDto> CreateAsync(ContactInformationCreateDto input)
{
return _contactInformationsAppService.CreateAsync(input);
}
}
How can i return the message to the consumer that Contact was not created because email already exists. Since the return type Task<ContactINformationDTO> i am not able to set the request as bad request and also how can we return a response from service to controller and then controller to consumer that email does not exist.
Thanks
8 Answer(s)
-
0
Its 403 which comes when user does not have permission
Markdown supported.Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post) -
0
when we say Busnessexception or friendly exception it results into status code 403 which is wrong code as user has permissions but contact cannot be added due to validation so we wanted to show a message with different status code than 403
Markdown supported.Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post) -
0
hi
You can try to override the
GetStatusCodemethod ofDefaultHttpExceptionStatusCodeFinderhttps://github.com/abpframework/abp/blob/dev/framework/src/Volo.Abp.AspNetCore/Volo/Abp/AspNetCore/ExceptionHandling/DefaultHttpExceptionStatusCodeFinder.cs#L70-L73
Markdown supported.Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post) -
0Markdown supported.Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)
-
0
ya it worked thanks
Markdown supported.Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)

