Skip to content
This repository has been archived by the owner on Feb 20, 2018. It is now read-only.

Commit

Permalink
valid-answer-on-create-session-request
Browse files Browse the repository at this point in the history
  • Loading branch information
sh0ked committed Dec 8, 2015
1 parent c2ee62c commit a3633b2
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions vmmaster/webdriver/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# coding: utf-8

from traceback import format_exc
from flask import Blueprint, current_app, request, jsonify, abort
from flask import Blueprint, current_app, request, jsonify

from vmmaster.webdriver import commands
import helpers
Expand All @@ -14,20 +14,24 @@
webdriver = Blueprint('webdriver', __name__)


def selenium_error_response(message, selenium_code=13, status_code=500):
error_context = {
'status': selenium_code,
'value': {
"message": "%s" % message
}
}
return jsonify(error_context), status_code


@webdriver.errorhandler(Exception)
def handle_errors(error):
tb = format_exc()
log.error(tb)
if hasattr(request, 'session'):
request.session.failed(tb)

error_context = {
'status': 13,
'value': {
"message": "%s" % tb
}
}
return jsonify(error_context), 500
return selenium_error_response(tb)


@webdriver.before_request
Expand Down Expand Up @@ -98,10 +102,14 @@ def create_session():
session = helpers.get_session()
commands.replace_platform_with_any(request)
status, headers, body = commands.start_session(request, session)

return helpers.form_response(status, headers, body)
else:
log.info("This request is aborted %s" % request)
abort(502)
message = "A new session could not be created " \
"because shutdown server in progress"

return selenium_error_response(message, status_code=502)


@webdriver.route("/session/<string:session_id>", methods=['GET'])
Expand Down

0 comments on commit a3633b2

Please sign in to comment.