Cleaned up code and added new ResponseExtensions to help with bad requests.
This commit is contained in:
parent
c4f4704441
commit
023654aba2
@ -225,5 +225,46 @@ namespace MontoyaTech.Rest.Net
|
|||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Sets the response to bad request with a text message saying the request was null or empty.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="response"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static HttpListenerResponse BadRequestNull(this HttpListenerResponse response)
|
||||||
|
{
|
||||||
|
return response.WithStatus(HttpStatusCode.BadRequest).WithText("Request was null or empty.");
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Sets the response to a bad request with a text message saying the request was invalid.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="response"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static HttpListenerResponse BadRequestInvalid(this HttpListenerResponse response)
|
||||||
|
{
|
||||||
|
return response.WithStatus(HttpStatusCode.BadRequest).WithText("Request data was invalid.");
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Sets the response to a bad request with a text message saying the request was out of range.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="response"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static HttpListenerResponse BadRequestOutOfRange(this HttpListenerResponse response)
|
||||||
|
{
|
||||||
|
return response.WithStatus(HttpStatusCode.BadRequest).WithText("Request data was out of range");
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Sets the response to a bad request with a text message saying a field in the request was out of range.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="response"></param>
|
||||||
|
/// <param name="fieldName"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static HttpListenerResponse BadRequestOutOfRange(this HttpListenerResponse response, string fieldName)
|
||||||
|
{
|
||||||
|
return response.WithStatus(HttpStatusCode.BadRequest).WithText($"{fieldName} in request is out of range.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -17,7 +17,7 @@
|
|||||||
<AssemblyName>MontoyaTech.Rest.Net</AssemblyName>
|
<AssemblyName>MontoyaTech.Rest.Net</AssemblyName>
|
||||||
<RootNamespace>MontoyaTech.Rest.Net</RootNamespace>
|
<RootNamespace>MontoyaTech.Rest.Net</RootNamespace>
|
||||||
<GenerateDocumentationFile>True</GenerateDocumentationFile>
|
<GenerateDocumentationFile>True</GenerateDocumentationFile>
|
||||||
<Version>1.1.6</Version>
|
<Version>1.1.7</Version>
|
||||||
<PackageReleaseNotes></PackageReleaseNotes>
|
<PackageReleaseNotes></PackageReleaseNotes>
|
||||||
<PackageIcon>Logo_Symbol_Black_Outline.png</PackageIcon>
|
<PackageIcon>Logo_Symbol_Black_Outline.png</PackageIcon>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user