Jump to content
Sign in to follow this  
Guest sky.sanders

Why does the Silverlight client throw a 404 when the actual status is 401 (or other)?

Recommended Posts

Guest sky.sanders

For example, if I try to log in with invalid credentials the exception thrown is an ApiException wrapped 404.

"CityIndex.JsonClient.ApiException: The remote server returned an error: NotFound. ---> System.Net.WebException: The remote server returned an error: NotFound. ---> System.Net.WebException: The remote server returned an error: NotFound.
   at System.Net.Browser.ClientHttpWebRequest.InternalEndGetResponse(IAsyncResult asyncResult)
   at System.Net.Browser.ClientHttpWebRequest.<>c__DisplayClass5.<EndGetResponse>b__4(Object sendState)
   at System.Net.Browser.AsyncHelper.<>c__DisplayClass2.<BeginOnUI>b__0(Object sendState)
   --- End of inner exception stack trace ---
   at System.Net.Browser.AsyncHelper.BeginOnUI(SendOrPostCallback beginMethod, Object state)
   at System.Net.Browser.ClientHttpWebRequest.EndGetResponse(IAsyncResult asyncResult)
   at CityIndex.JsonClient.Client.<>c__DisplayClassc`1.<EnqueueRequest>b__b(IAsyncResult ar, RequestHolder requestHolder)
   --- End of inner exception stack trace ---
   at CityIndex.JsonClient.ApiAsyncResult`1.End()
   at CityIndex.JsonClient.Client.EndRequest[TDTO](ApiAsyncResult`1 asyncResult)
   at CIAPI.Rpc.Client.EndRequest[TDTO](ApiAsyncResult`1 asyncResult)
   at CIAPI.Rpc.Client.EndLogIn(ApiAsyncResult`1 asyncResult)
   at CIAPI.Silverlight.TestsMS.IssueResolutionScratchpadFixture.<>c__DisplayClass2.<>c__DisplayClass4.<Foo>b__1()"

Share this post


Link to post
Guest sky.sanders

Silverlight is not very informative in exception reporting and will fall back on SecurityException and WebException (not found) for many issues that are in no way related.

The ApiException.ResponseText, if present, should always contain JSON from the server explaining the exception.

e.g.

{"ErrorCode":4010,"ErrorMessage":"The credentials used to authenticate are invalid.  Either the username, password or both are incorrect."}

You may either do a simple regex on the text or deserialize it into an ErrorResponseDTO.

In an upcoming push this deserialization will be be handled for you and you may simply check a member of the ApiException for details.

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  
×