How do we return a HTTP status code with the object returned in REST API using VB.NET Framework 4.0?
I have Googled this and found some solutions like throwing the error before returning the object as below:
Public Function InfoAndTerms(ByVal Lang As String) As Information() Implements IService.InfoAndTerms
Dim result() As Information
Try
' Do something and fill result
Catch ex As Exception
Throw New System.Web.HttpException(500, "Error - InfoAndTerms")
Finally
InfoAndTerms = result
End Try
End Function
But in my case this function is always returning status 400 instead of 500 and I don't know why.
How do I fix this problem? Is there any other way to do that?