1
I have the following method that makes a request for Delete
to my WebApi
:
[HttpPost]
public async Task<IActionResult> Delete(int id, IFormCollection frmCollection)
{
HttpClient httpClient = new HttpClient();
httpClient.BaseAddress = new Uri("http://localhost:6000/api/");
var resposta = await httpClient.DeleteAsync($"cencus/{id}");
//... TRATAR A EXCEPTION AQUI
}
The return method of my API is as follows:
[HttpDelete("{id}")]
public IActionResult Delete(int id)
{
DatabaseConnector dbConn = new DatabaseConnector();
try
{
int affected = dbConn.Connection
.Execute($"DELETE FROM CENCUS WHERE CODCEN = {id}");
if (affected > 0)
{
return NoContent(); //203
}
else
{
return NotFound(); //404
}
}
catch (Exception exp)
{
return Conflict(exp); //409
}
finally
{
dbConn.Dispose();
}
}
My question is: in case exception
when executing the command SQL
, how I will access the information as a message from Exception
in response?
Return the error status and add the message you want...
– Leandro Angelo
you here already send the problem to your Webapi (
return Conflict(exp); //409
) although I don’t know if that’s good ... !– novic
What is your question, specifically? I can’t understand what you intend to do...
– Jéf Bueno