messagebird / csharp-rest-api

This repository contains the open source C# client for MessageBird's REST API.
ISC License
54 stars 60 forks source link

List SMS fails when originator in response is invalid. #120

Open SebastianStehle opened 2 years ago

SebastianStehle commented 2 years ago

Hi, I just query SMS messages:

var messageBird = Client.CreateDefault(AccessKey);

var messages = messageBird.ListMessages(string.Empty, 200);

And I got the following exception in my unit test:

[xUnit.net 00:00:17.17]     TestSuite.ApiTests.SmsTests.Should_send_sms_with_template [FAIL]
  Failed TestSuite.ApiTests.SmsTests.Should_send_sms_with_template [15 s]
  Error Message:
   MessageBird.Exceptions.ErrorException : Received response in an unexpected format!
---- Newtonsoft.Json.JsonSerializationException : Error setting value to 'Originator' on 'MessageBird.Objects.Message'.
-------- System.ArgumentException : Originator can only contain numeric or whitespace separated alphanumeric characters.
  Stack Trace:
     at MessageBird.Resources.Resource.Deserialize(String resource)
   at MessageBird.Net.RestClient.RequestWithResource[T](String method, String uri, T resource, HttpStatusCode expectedHttpStatusCode)
   at MessageBird.Net.RestClient.Retrieve[T](T resource)
   at MessageBird.Client.ListMessages(String status, Int32 limit, Int32 offset)
   at TestSuite.ApiTests.SmsTests.Should_send_sms_with_template() in /src/backend/tools/TestSuite/TestSuite.ApiTests/SmsTests.cs:line [133](https://github.com/notifo-io/notifo/runs/6162285497?check_suite_focus=true#step:10:133)
--- End of stack trace from previous location ---
----- Inner Stack Trace -----
   at Newtonsoft.Json.Serialization.ExpressionValueProvider.SetValue(Object target, Object value)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.SetPropertyValue(JsonProperty property, JsonConverter propertyConverter, JsonContainerContract containerContract, JsonProperty containerProperty, JsonReader reader, Object target)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateObject(Object newObject, JsonReader reader, JsonObjectContract contract, JsonProperty member, String id)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateList(IList list, JsonReader reader, JsonArrayContract contract, JsonProperty containerProperty, String id)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateList(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, Object existingValue, String id)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.SetPropertyValue(JsonProperty property, JsonConverter propertyConverter, JsonContainerContract containerContract, JsonProperty containerProperty, JsonReader reader, Object target)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateObject(Object newObject, JsonReader reader, JsonObjectContract contract, JsonProperty member, String id)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Populate(JsonReader reader, Object target)
   at Newtonsoft.Json.JsonSerializer.PopulateInternal(JsonReader reader, Object target)
   at Newtonsoft.Json.JsonConvert.PopulateObject(String value, Object target, JsonSerializerSettings settings)
   at Newtonsoft.Json.JsonConvert.PopulateObject(String value, Object target)
   at MessageBird.Resources.Resource.Deserialize(String resource)
----- Inner Stack Trace -----
   at MessageBird.Utilities.ParameterValidator.IsValidOriginator(String originator)
   at MessageBird.Objects.Message.set_Originator(String value)
   at Newtonsoft.Json.Serialization.ExpressionValueProvider.SetValue(Object target, Object value)
[xUnit.net 00:00:28.24]     TestSuite.ApiTests.SmsTests.Should_send_sms_without_template [FAIL]
  Failed TestSuite.ApiTests.SmsTests.Should_send_sms_without_template [11 s]
  Error Message:
   MessageBird.Exceptions.ErrorException : Received response in an unexpected format!
---- Newtonsoft.Json.JsonSerializationException : Error setting value to 'Originator' on 'MessageBird.Objects.Message'.
-------- System.ArgumentException : Originator can only contain numeric or whitespace separated alphanumeric characters.
  Stack Trace:
     at MessageBird.Resources.Resource.Deserialize(String resource)
   at MessageBird.Net.RestClient.RequestWithResource[T](String method, String uri, T resource, HttpStatusCode expectedHttpStatusCode)
   at MessageBird.Net.RestClient.Retrieve[T](T resource)
   at MessageBird.Client.ListMessages(String status, Int32 limit, Int32 offset)
   at TestSuite.ApiTests.SmsTests.Should_send_sms_without_template() in /src/backend/tools/TestSuite/TestSuite.ApiTests/SmsTests.cs:line 231
--- End of stack trace from previous location ---
----- Inner Stack Trace -----
   at Newtonsoft.Json.Serialization.ExpressionValueProvider.SetValue(Object target, Object value)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.SetPropertyValue(JsonProperty property, JsonConverter propertyConverter, JsonContainerContract containerContract, JsonProperty containerProperty, JsonReader reader, Object target)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateObject(Object newObject, JsonReader reader, JsonObjectContract contract, JsonProperty member, String id)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateList(IList list, JsonReader reader, JsonArrayContract contract, JsonProperty containerProperty, String id)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateList(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, Object existingValue, String id)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.SetPropertyValue(JsonProperty property, JsonConverter propertyConverter, JsonContainerContract containerContract, JsonProperty containerProperty, JsonReader reader, Object target)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateObject(Object newObject, JsonReader reader, JsonObjectContract contract, JsonProperty member, String id)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Populate(JsonReader reader, Object target)
   at Newtonsoft.Json.JsonSerializer.PopulateInternal(JsonReader reader, Object target)
   at Newtonsoft.Json.JsonConvert.PopulateObject(String value, Object target, JsonSerializerSettings settings)
   at Newtonsoft.Json.JsonConvert.PopulateObject(String value, Object target)
   at MessageBird.Resources.Resource.Deserialize(String resource)
----- Inner Stack Trace -----
   at MessageBird.Utilities.ParameterValidator.IsValidOriginator(String originator)
   at MessageBird.Objects.Message.set_Originator(String value)
   at Newtonsoft.Json.Serialization.ExpressionValueProvider.SetValue(Object target, Object value)

It just started recently, so I guess I have made a request before (or someone else). It is a shared account between some projects.

But if you store an invalid originator, you also have to return it.