how to configure to return 408 instead of 500 when Azure web app request timed out in 230 seconds

60 Views Asked by At

Azure web app has a default setting of request timeout at 230 seconds. we have an API which serves customer query, so its time depends on the customers query input. if the query is simple, API will return in few ms, if query is complex it takes more time. sometimes it takes more than 230 second, so the request get timed out and return 500. our requirement is to return 408 time out error code, when it takes more than 230 second. is there any way to configure that?

so our concern is not about time out, but about the error code, we need to return 408 instead of 500 after 230 sec

Azure web app has a default setting of request timeout at 230 seconds. we have an API which serves customer query, so its time depends on the customers query input. if the query is simple, API will return in few ms, if query is complex it takes more time. sometimes it takes more than 230 second, so the request get timed out and return 500. our requirement is to return 408 time out error code, when it takes more than 230 second. is there any way to configure that? so our concern is not about time out, but about the error code, we need to return 408 instead of 500 after 230 sec

1

There are 1 best solutions below

1
On

According to this MS Q & A answer by Venkatesh Dodda.

You can add a Custom Error page as 408.html in your Website > wwwroot And edit your web.config to fetch the 408.html custom error page during timeout.

I added 408.html page in my Azure Web app > Advanced Tools > Go > Kudu > Tools > Zip push deploy > And added one File with 408.html name and code like below:-

<!DOCTYPE html>
<html>
<head>
    <title>Request Timeout (408)</title>
</head>
<body>
    <h1>Request Timeout (408)</h1>
    <p>The server was unable to respond to your request in a timely manner. Please try again later or get in touch with the site administrator.</p>
</body>
</html>

enter image description here

Edited web.config with the path set to the 408.html file like below:-

web.config:-

<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <system.webServer>
        <httpErrors errorMode="Custom" defaultResponseMode="ExecuteURL">
            <remove statusCode="408" subStatusCode="-1" />
            <error statusCode="408" path="/408.html" responseMode="ExecuteURL" />
        </httpErrors>
    </system.webServer>
  <location path="." inheritInChildApplications="false">
    <system.webServer>
      <handlers>
        <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" />
      </handlers>
      <aspNetCore processPath="dotnet" arguments=".\WebApplication22.dll" stdoutLogEnabled="false" stdoutLogFile="\\?\%home%\LogFiles\stdout" hostingModel="inprocess" />
    </system.webServer>
  </location>
</configuration>

As an alternative, You can Upgrade your Web app to Premium plan and make use of custom Error pages preview feature. As this Feature is still in Preview you can only edit 403, 502, 503 Error pages as 408 is not supported yet, Refer below:-

enter image description here

enter image description here

Another alternative is to create a 408.html page in your Local Web app and then Add the path to the folder in web.config.