Unified Response Error Handling Mechanism

AMicroblogAPI exposes an Unified Response Error Handling Mechanism for app developer to handle the response error in a configurable unified style.
This mechanism is useful especially in the cases that
  • More than one APIs return the same error code and you don't want to copy and paste the same error handling code from one place to another;
  • Or you want to perform additional exception handling logic (i.e: logging) against a specified type of error(i.e: 400 ) or a concrete error(i.e: 40023) or even all errors.
To use Unified Response Error Handling Mechanism, do the followings:
1. Implements a Response Error Handler which implemets interface IResponseErrorHandler
    public interface IResponseErrorHandler
        /// <summary>
        /// Handles the response error with the <paramref name="errorData"/>.
        /// </summary>
        /// <param name="errorData">The contextual data of the response error.</param>
        void Handle(ResponseErrorData errorData);
2. Configures the Response Error Handler in application config (i.e: app.config)
<?xml version="1.0"?>
    <section name="amicroblogAPI" type="AMicroblogAPI.Common.AMicroblogAPIConfigurationSection, AMicroblogAPI"/>
    <responseErrorHandling enabled="true">
        <!--Handles all 400 type error (if you want handle all error simply set errorCode="*")-->
        <handler type="MyHandlerClass, MyHandlerAssembly" errorCode="^400"/>
This mechanism can be turned off by simply setting enabled="false" on the responseErrorHandling node.

Last edited Sep 2, 2011 at 1:36 PM by shoocstorm, version 1


No comments yet.