mirror of
https://github.com/ail-project/ail-framework.git
synced 2024-11-10 08:38:28 +00:00
fix: [api] fix errors handler 404 405, return json
This commit is contained in:
parent
79ad809d2c
commit
918b4c28ed
3 changed files with 18 additions and 3 deletions
|
@ -49,7 +49,7 @@ def check_import_status(UUID):
|
||||||
|
|
||||||
processing = r_serv_log_submit.get(UUID + ':processing')
|
processing = r_serv_log_submit.get(UUID + ':processing')
|
||||||
if not processing:
|
if not processing:
|
||||||
return ({'status': 'error', 'reason': 'Unknow uuid'}, 400)
|
return ({'status': 'error', 'reason': 'Unknown uuid'}, 400)
|
||||||
|
|
||||||
# nb_total = r_serv_log_submit.get(UUID + ':nb_total')
|
# nb_total = r_serv_log_submit.get(UUID + ':nb_total')
|
||||||
# nb_sucess = r_serv_log_submit.get(UUID + ':nb_sucess')
|
# nb_sucess = r_serv_log_submit.get(UUID + ':nb_sucess')
|
||||||
|
|
|
@ -5,6 +5,7 @@ import os
|
||||||
import re
|
import re
|
||||||
import sys
|
import sys
|
||||||
import ssl
|
import ssl
|
||||||
|
import json
|
||||||
import time
|
import time
|
||||||
|
|
||||||
import redis
|
import redis
|
||||||
|
@ -13,7 +14,7 @@ import logging
|
||||||
import logging.handlers
|
import logging.handlers
|
||||||
import configparser
|
import configparser
|
||||||
|
|
||||||
from flask import Flask, render_template, jsonify, request, Request, session, redirect, url_for
|
from flask import Flask, render_template, jsonify, request, Request, Response, session, redirect, url_for
|
||||||
from flask_login import LoginManager, current_user, login_user, logout_user, login_required
|
from flask_login import LoginManager, current_user, login_user, logout_user, login_required
|
||||||
|
|
||||||
import bcrypt
|
import bcrypt
|
||||||
|
@ -291,7 +292,21 @@ def searchbox():
|
||||||
|
|
||||||
# ========== ERROR HANDLER ============
|
# ========== ERROR HANDLER ============
|
||||||
|
|
||||||
|
@app.errorhandler(405)
|
||||||
|
def _handle_client_error(e):
|
||||||
|
if request.path.startswith('/api/'):
|
||||||
|
return Response(json.dumps({"status": "error", "reason": "Method Not Allowed: The method is not allowed for the requested URL"}, indent=2, sort_keys=True), mimetype='application/json'), 405
|
||||||
|
else:
|
||||||
|
return e
|
||||||
|
|
||||||
@app.errorhandler(404)
|
@app.errorhandler(404)
|
||||||
|
def error_page_not_found(e):
|
||||||
|
if request.path.startswith('/api/'):
|
||||||
|
return Response(json.dumps({"status": "error", "reason": "404 Not Found"}, indent=2, sort_keys=True), mimetype='application/json'), 404
|
||||||
|
else:
|
||||||
|
# avoid endpoint enumeration
|
||||||
|
return page_not_found(e)
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
def page_not_found(e):
|
def page_not_found(e):
|
||||||
# avoid endpoint enumeration
|
# avoid endpoint enumeration
|
||||||
|
|
|
@ -627,7 +627,7 @@ def import_item_uuid(UUID):
|
||||||
HTTP Status Code: 400
|
HTTP Status Code: 400
|
||||||
|
|
||||||
{'status': 'error', 'reason': 'Invalid uuid'}
|
{'status': 'error', 'reason': 'Invalid uuid'}
|
||||||
{'status': 'error', 'reason': 'Unknow uuid'}
|
{'status': 'error', 'reason': 'Unknown uuid'}
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue