I had the same problem in the same scenario. However, in this case, you need to return some content in the response that will be shown, and not throw an exception. Therefore, based on this, I would change your code to the following:
catch (Exception) { var response = context.Request.CreateResponse(httpStatusCode.Unauthorized); response.Content = new StringContent("User with api key is not valid"); context.Response = response; }
So, with this change, you are now returning your answer, with content that will be displayed instead of a blank screen.
source share