Skip to content

Latest commit

 

History

History
51 lines (33 loc) · 1.73 KB

RequestContext.md

File metadata and controls

51 lines (33 loc) · 1.73 KB

Azure client RequestContext samples

NOTE: Samples in this file apply only to packages that follow Azure SDK Design Guidelines. Names of such packages usually start with Azure.

Customize Error Handling

You can suppress the exception a service method throws when an error response is returned.

RequestContext context = new RequestContext { ErrorOptions = ErrorOptions.NoThrow };

Add Policy For Request

You can add various types of policies for one request.

Add Policy Per Call

Add a policy to set the request header once per pipeline invocation (service call).

var context = new RequestContext();
context.AddPolicy(new AddHeaderPolicy("PerCallHeader", "Value"), HttpPipelinePosition.PerCall);

Add Policy Per Retry

Add a policy to set the request header every time request is retried.

var context = new RequestContext();
context.AddPolicy(new AddHeaderPolicy("PerRetryHeader", "Value"), HttpPipelinePosition.PerRetry);

Add Policy Before Transport

Add a policy to set the request header before the request is sent by the transport.

var context = new RequestContext();
context.AddPolicy(new AddHeaderPolicy("BeforeTransportHeader", "Value"), HttpPipelinePosition.BeforeTransport);

Customize Category Of Response By Status Code

You can change the category of response by the returned status code. This can be used to treat error responses as success responses in logging and distributed tracing.

var context = new RequestContext();
context.AddClassifier(404, isError: false);