Created
April 7, 2017 16:08
-
-
Save RLittlesII/8a3f616848483d0b5d1bc84b1302b0b8 to your computer and use it in GitHub Desktop.
Configure WebApi Custom Errors
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <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