Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RLittlesII/8a3f616848483d0b5d1bc84b1302b0b8 to your computer and use it in GitHub Desktop.
Save RLittlesII/8a3f616848483d0b5d1bc84b1302b0b8 to your computer and use it in GitHub Desktop.
Configure WebApi Custom Errors
/// <summary>
/// Configures the Web Api custom errors.
/// </summary>
/// <param name="config">The configuration.</param>
/// <exception cref="System.ArgumentOutOfRangeException"></exception>
public static void ConfigureErrors(HttpConfiguration config)
{
var customErrors = (CustomErrorsSection) ConfigurationManager.GetSection("system.web/customErrors");
switch (customErrors.Mode)
{
case CustomErrorsMode.RemoteOnly:
config.IncludeErrorDetailPolicy = IncludeErrorDetailPolicy.LocalOnly;
break;
case CustomErrorsMode.On:
config.IncludeErrorDetailPolicy = IncludeErrorDetailPolicy.Never;
break;
case CustomErrorsMode.Off:
config.IncludeErrorDetailPolicy = IncludeErrorDetailPolicy.Always;
break;
default:
throw new ArgumentOutOfRangeException();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment