container-server/proxy/errorpages/generate.py

108 lines
3.4 KiB
Python
Raw Normal View History

2022-06-19 13:18:17 +02:00
from string import Template
import datetime
import os
dist_dir = 'dist'
errors = {
400: {
'code': '400',
'emoji': '🚫',
'title': 'Bad Request',
'description': 'The server cannot or will not process the request due to something that is perceived to be a client error (e.g. malformed request syntax).',
},
401: {
'code': '401',
'emoji': '🔐',
'title': 'Unauthorized',
'description': 'The request has not been applied because it lacks valid authentication credentials for the target resource.',
},
403: {
'code': '403',
'emoji': '',
'title': 'Forbidden',
'description': 'The server understood the request but refuses to authorize it.',
},
404: {
'code': '404',
'emoji': '',
'title': 'Not Found',
'description': 'The requested page could not be found.',
},
405: {
'code': '405',
'emoji': '',
'title': 'Method Not Allowed',
'description': 'The method received in the request-line is known by the origin server but not supported by the target resource.',
},
408: {
'code': '408',
'emoji': '⌛️',
'title': 'Request Timeout',
'description': 'The server timed out waiting for the request.',
},
413: {
'code': '413',
'emoji': '⌛️',
'title': 'Payload Too Large',
'description': 'The server will not accept the request because the request entity is too large.',
},
418: {
'code': '418',
'emoji': '🍵',
'title': 'I\'m a Teapot',
'description': 'Any attempt to brew coffee with a teapot should result in the error code "418 I\'m a teapot". The resulting entity body MAY be short and stout.',
},
429: {
'code': '429',
'emoji': '🌋',
'title': 'Too Many Requests',
'description': 'The user has sent too many requests in a given amount of time.',
},
500: {
'code': '500',
'emoji': '💣',
'title': 'Internal Server Error',
'description': 'The server encountered an unexpected condition that prevented it from fulfilling the request.',
},
501: {
'code': '501',
'emoji': '📭',
'title': 'Not Implemented',
'description': 'The server does not support the functionality required to fulfill the request.',
},
502: {
'code': '502',
'emoji': '🚧',
'title': 'Bad Gateway',
'description': 'The server was acting as a gateway or proxy and received an invalid response from the upstream server.',
},
503: {
'code': '503',
'emoji': '🚨',
'title': 'Service Unavailable',
'description': 'The service is currently unavailable.',
},
504: {
'code': '504',
'emoji': '',
'title': 'Gateway Timeout',
'description': 'TThe server was acting as a gateway or proxy and did not receive a timely response from the upstream server.',
},
}
date = {
'date': datetime.datetime.now().isoformat()
}
print('== Creating output dir')
os.mkdir(f'./{dist_dir}')
print('== Creating error pages')
with open('./template.html', 'r') as f:
template = Template(f.read())
for key, content in errors.items():
print(f' - {key}')
result = template.substitute(content | date)
with open(f'./{dist_dir}/{key}.html', 'w') as out:
out.write(result)