from flask import render_template
from oxyapp import app


# Error handlers - à modifier pour faire une erreur groupé avec un JSON
# Différentes pages erreurs
@app.errorhandler(400)
def session_out(e):
    error_code = 404
    unknow_user = 'Unknow User'
    error_message = str("Bad Request")
    templateData = {'error_code': error_code, 'nom': unknow_user, 'error_message': error_message}
    return render_template('errors/errorPage.html', **templateData), 400


@app.errorhandler(403)
def session_out(e):
    error_code = 403
    unknow_user = 'Unknow User'
    error_message = str("Forbiden")
    templateData = {'error_code': error_code, 'nom': unknow_user, 'error_message': error_message}
    return render_template('errors/errorPage.html', **templateData)


@app.errorhandler(404)
def session_out(e):
    error_code = 404
    unknow_user = 'Unknow User'
    error_message = str("Page Not Found")
    templateData = {'error_code': error_code, 'nom': unknow_user, 'error_message': error_message}
    return render_template('errors/errorPage.html', **templateData), 404


@app.errorhandler(405)
def session_out(e):
    error_code = 405
    unknow_user = 'Unknow User'
    error_message = str("Method not found")
    templateData = {'error_code': error_code, 'nom': unknow_user, 'error_message': error_message}
    return render_template('errors/errorPage.html', **templateData), 405


@app.errorhandler(500)
def session_out(e):
    error_code = 500
    unknow_user = 'Unknow User'
    error_message = str("Internal Server Error")
    templateData = {'error_code': error_code, 'nom': unknow_user, 'error_message': error_message}
    return render_template('errors/errorPage.html', **templateData), 500


@app.errorhandler(503)
def session_out(e):
    error_code = 503
    unknow_user = 'Unknow User'
    error_message = str("Service Unvailable")
    templateData = {'error_code': error_code, 'nom': unknow_user, 'error_message': error_message}
    return render_template('errors/errorPage.html', **templateData), 503
