using System;
using System.Net;
namespace PSProxmoxVE.Core.Exceptions
{
/// Exception thrown when the Proxmox VE API returns an error response.
public class PveApiException : Exception
{
/// The HTTP status code returned by the PVE API.
public HttpStatusCode StatusCode { get; }
/// The API resource path that was requested.
public string Resource { get; }
/// The HTTP method used for the request (GET, POST, PUT, DELETE).
public string HttpMethod { get; }
/// Initializes a new instance for a failed PVE API request.
/// The HTTP status code returned.
/// The error message from the API.
/// The API resource path that was requested.
/// The HTTP method used.
public PveApiException(HttpStatusCode statusCode, string message, string resource, string httpMethod)
: base($"PVE API error ({(int)statusCode} {statusCode}) on {httpMethod} {resource}: {message}")
{
StatusCode = statusCode;
Resource = resource;
HttpMethod = httpMethod;
}
/// Initializes a new instance for a failed PVE API request, with an inner exception.
/// The HTTP status code returned.
/// The error message from the API.
/// The API resource path that was requested.
/// The HTTP method used.
/// The exception that caused this failure.
public PveApiException(HttpStatusCode statusCode, string message, string resource, string httpMethod, Exception innerException)
: base($"PVE API error ({(int)statusCode} {statusCode}) on {httpMethod} {resource}: {message}", innerException)
{
StatusCode = statusCode;
Resource = resource;
HttpMethod = httpMethod;
}
}
}