Reputation: 353
I'm new on DotNet Framework (i'm using code igniter before), I try to post data into my SQL Server. This is my controller
[HttpPost]
public Response Post([FromBody] Log_Ups_User log_user)
{
Response response = new Response();
try
{
LogAccessLayer log = new LogAccessLayer();
log.AddUpsUser(log_user);
response.data = null;
response.message = "Inserted";
response.status = "Ok";
}
catch
{
response.data = null;
response.message = "Error";
response.status = "Sial";
}
return response;
}
then my Response.cs
public class Response
{
public string status { get; set; }
public object data { get; set; }
public string message { get; set; }
}
I post the data using Postman and it return
"status": "Sial", "data": null, "message": "Error"
But I don't know which part or which line of my code that cause error. How to return error that can give me some information.
Thanks
Upvotes: 0
Views: 26
Reputation: 725
Try to use Exceptional block into your code. From your example try to modify your code just likes this. So you can see error message..
public Response Post([FromBody] Log_Ups_User log_user)
{
Response response = new Response();
try
{
LogAccessLayer log = new LogAccessLayer();
log.AddUpsUser(log_user);
response.data = null;
response.message = "Inserted";
response.status = "Ok";
}
catch(Exceptional ex)
{
response.data = null;
response.message = ex.ToString();
response.status = "Sial";
}
return response;
}
Upvotes: 1