public void CanSerializerSingleErrorFromObject() { var error = new JsonApiError { Status = "422", Source = new JsonApiErrorSource { Pointer = "/data/attributes/firstName" }, Title = "Invalid Attribute", Detail = "First name must contain at least three characters." }; var json = error.Serialize(); Assert.Equal(@" { 'errors': [ { 'status': '422', 'title': 'Invalid Attribute', 'detail': 'First name must contain at least three characters.', 'source': { 'pointer': '/data/attributes/firstName' } } ] }".Format(), json, JsonStringEqualityComparer.Default); }
public JsonApiError(HttpError error, IErrorIdProvider idProvider) { Id = idProvider.GenerateId(error); Title = error.ExceptionType ?? error.Message; Status = "500"; Detail = error.ExceptionMessage ?? error.MessageDetail; StackTrace = error.StackTrace; if (error.InnerException != null) Inner = new JsonApiError(error.InnerException, idProvider); }
public void SerializingNullErrorInArrayThrows() { var errors = new JsonApiError[] { null }; var exception = Record.Exception(() => errors.Serialize()); Assert.NotNull(exception); Assert.IsType <JsonApiFormatException>(exception); }
public JsonApiError(HttpError error) { Title = error.ExceptionType ?? error.Message; Status = "500"; Detail = error.ExceptionMessage ?? error.MessageDetail; StackTrace = error.StackTrace; if (error.InnerException != null) { Inner = new JsonApiError(error.InnerException); } }
public JsonApiError(HttpError error, IErrorIdProvider idProvider) { Id = idProvider.GenerateId(error); Title = error.ExceptionType ?? error.Message; Status = "500"; Detail = error.ExceptionMessage ?? error.MessageDetail; StackTrace = error.StackTrace; if (error.InnerException != null) { Inner = new JsonApiError(error.InnerException, idProvider); } }
public void SerializeError(object error, Stream writeStream, JsonWriter writer, JsonSerializer serializer) { var httpError = error as HttpError; if (httpError == null) throw new Exception("Unsupported error type."); writer.WriteStartObject(); writer.WritePropertyName("errors"); var jsonApiError = new JsonApiError(httpError, _errorIdProvider); serializer.Serialize(writer, new[] { jsonApiError }); writer.WriteEndObject(); }
/// <summary> /// Map the HTTP error to a JsonApiError. /// </summary> /// <param name="httpError">The HTTP error to map.</param> /// <returns>The JSON API error that was mapped from the HTTP Error.</returns> static JsonApiError Map(HttpError httpError) { var error = new JsonApiError { Status = "500", Code = "500" }; if (httpError.TryGetValue("Message", out object value)) { error.Title = value.ToString(); } if (httpError.TryGetValue("ExceptionMessage", out value)) { error.Detail = value.ToString(); } return(error); }
public void SerializeError(object error, Stream writeStream, JsonWriter writer, JsonSerializer serializer) { var httpError = error as HttpError; if (httpError == null) { throw new Exception("Unsupported error type."); } writer.WriteStartObject(); writer.WritePropertyName("errors"); var jsonApiError = new JsonApiError(httpError, _errorIdProvider); serializer.Serialize(writer, new[] { jsonApiError }); writer.WriteEndObject(); }
public JsonApiException() { this._error = new JsonApiError(); }
public JsonApiException(JsonApiError error) { this._error = error; }