5.19Ensuring Request Success

Updated on Aug 20, 2026~3 min read

After adding the EnsureSuccessStatusCodeAttribute attribute, when the HTTP response status code is outside the 200-299 range (that is, when the IsSuccessStatusCode property is false), an exception will be thrown automatically.

HTTP declarative requests ensure request success via the EnsureSuccessStatusCodeAttribute attribute. The corresponding HTTP declarative extractor is implemented as the EnsureSuccessStatusCodeDeclarativeExtractor type, which is responsible for parsing the EnsureSuccessStatusCodeAttribute attribute and building the HttpRequestBuilder instance configuration required to ensure request success.

cs
// Apply on the interface definition, affecting all methods[EnsureSuccessStatusCode]public interface IHttpService : IHttpDeclarative{    // Apply on a method    [EnsureSuccessStatusCode]    [Get("https://furion.net/")]    Task<string> GetStringAsync();    [EnsureSuccessStatusCode(false)]   // Disable validation    [Get("https://furion.net/")]    Task<string> GetStringAsync();}

EnsureSuccessStatusCodeAttribute includes the following constructors and properties:

  • Constructors:

    • new(): applies to a method or interface, ensuring request success.
    • new(enabled): applies to a method or interface, setting whether to ensure request success.
  • Properties:

    • Enabled: whether to enable (bool type); the default value is true (enabled).