I am using this method from the azure mobile services tutorial:
await todoTable.LookupAsync(id)
. I have 2 rows in a table of id 1,2.
If i do await todoTable.LookupAsync(1)
, it works and return the record. If i do
await todoTable.LookupAsync(8)
to see how it's going to handle null, it just blows up with Not Found exception.
Thanks for help on this.
NULL
would mean there is a record forid = 8
, but its value is `NULL'. But in your case you do not have a record. Which is different.What you observe is what you should observe if you do not have a record.
And this is a standard for REST based HTTP services. If record is not there, you get an
HTTP 404
from the service.Azure mobile services is nothing more than a combination of Web API and a wrapping (plumbing) code for your application. And every Web API call to a non-existent record would result into an HTTP 404 error.
And as already said in the comments, you should wrap your code around
try - catch
blocks and inspect the exception.In .NET 4.5/4.6 there is new HttpClient type along with HttpResponseMessage and HttpRequestMessatge. The former has EnsureSuccessStatusCode() method. Which, if called will trigger exception.
In the older versions of the Framework there WebClient class, which would throw an exception if the HTTP status code is not 200.
So, again, at the end - you observe absolutely normal behavoir. Just have to read a little more about HTTP REST services, HTTP VERBS and HTTP Status Codes. Then also understand how the particular framework you use (.NET) handles the HTTP Status Codes.