| | 1 | | // Copyright (c) Microsoft Corporation. All rights reserved. |
| | 2 | | // Licensed under the MIT License. |
| | 3 | |
|
| | 4 | | using System; |
| | 5 | |
|
| | 6 | | namespace Azure |
| | 7 | | { |
| | 8 | | internal class NoBodyResponse<T> : Response<T> |
| | 9 | | { |
| | 10 | | private readonly Response _response; |
| | 11 | |
|
| 0 | 12 | | public NoBodyResponse(Response response) |
| | 13 | | { |
| 0 | 14 | | _response = response; |
| 0 | 15 | | } |
| | 16 | |
|
| | 17 | | public override T Value |
| | 18 | | { |
| | 19 | | get |
| | 20 | | { |
| 0 | 21 | | throw new ResponseBodyNotFoundException(_response.Status, _response.ReasonPhrase); |
| | 22 | | } |
| | 23 | | } |
| | 24 | |
|
| 0 | 25 | | public override Response GetRawResponse() => _response; |
| | 26 | |
|
| | 27 | | public override string ToString() |
| | 28 | | { |
| 0 | 29 | | return $"Status: {GetRawResponse().Status}, Service returned no content"; |
| | 30 | | } |
| | 31 | |
|
| | 32 | | #pragma warning disable CA1064 // Exceptions should be public |
| | 33 | | private class ResponseBodyNotFoundException : Exception |
| | 34 | | #pragma warning restore CA1064 // Exceptions should be public |
| | 35 | | { |
| 0 | 36 | | public int Status { get; } |
| | 37 | |
|
| | 38 | | public ResponseBodyNotFoundException(int status, string message) |
| 0 | 39 | | : base(message) |
| | 40 | | { |
| 0 | 41 | | Status = status; |
| 0 | 42 | | } |
| | 43 | | } |
| | 44 | | } |
| | 45 | | } |