Skip to content

Commit 82cf122

Browse files
committed
Enhance Debug experience w/ RestResponse
Make the default view of the debug pane provide helpful data about the response so that you don't have to 'dig' into it to see success/failure
1 parent 658f098 commit 82cf122

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

RestSharp/RestResponse.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,15 @@
1818
using System.Collections.Generic;
1919
using System.Net;
2020
using RestSharp.Extensions;
21+
using System.Diagnostics;
2122

2223
namespace RestSharp
2324
{
25+
2426
/// <summary>
2527
/// Base class for common properties shared by RestResponse and RestResponse[[T]]
2628
/// </summary>
29+
[DebuggerDisplay("{DebuggerDisplay()}")]
2730
public abstract class RestResponseBase
2831
{
2932
private string _content;
@@ -133,12 +136,23 @@ public ResponseStatus ResponseStatus
133136
/// The exception thrown during the request, if any
134137
/// </summary>
135138
public Exception ErrorException { get; set; }
139+
140+
141+
/// <summary>
142+
/// Assists with debugging responses by displaying in the debugger output
143+
/// </summary>
144+
/// <returns></returns>
145+
protected string DebuggerDisplay()
146+
{
147+
return string.Format("{0}: {1} ({2})", StatusCode, ContentType, ContentLength);
148+
}
136149
}
137150

138151
/// <summary>
139152
/// Container for data sent back from API including deserialized data
140153
/// </summary>
141154
/// <typeparam name="T">Type of data to deserialize to</typeparam>
155+
[DebuggerDisplay("{DebuggerDisplay()}")]
142156
public class RestResponse<T> : RestResponseBase, IRestResponse<T>
143157
{
144158
/// <summary>
@@ -171,5 +185,6 @@ public static explicit operator RestResponse<T>(RestResponse response)
171185
/// <summary>
172186
/// Container for data sent back from API
173187
/// </summary>
188+
[DebuggerDisplay("{DebuggerDisplay()}")]
174189
public class RestResponse : RestResponseBase, IRestResponse { }
175190
}

0 commit comments

Comments
 (0)