Skip to content

Commit

Permalink
Merge pull request #80 from Geode-solutions/next
Browse files Browse the repository at this point in the history
Next
  • Loading branch information
JulienChampagnol authored May 27, 2024
2 parents 634980a + 040c409 commit 5520ba3
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 16 deletions.
19 changes: 19 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,25 @@



## v4.2.0-rc.1 (2024-05-27)

### Feature

* feat(error_handler): Add handler ([`4dd7dfb`](https://github.com/Geode-solutions/OpenGeodeWeb-Back/commit/4dd7dfb8998403c27c2d04dfbdd64c16662704b1))

### Unknown

* Merge pull request #79 from Geode-solutions/feat_config

added test + handle_exception function ([`d0546b8`](https://github.com/Geode-solutions/OpenGeodeWeb-Back/commit/d0546b8203f48aac44491529b08f6d52b257767a))

* requirements ([`78faf30`](https://github.com/Geode-solutions/OpenGeodeWeb-Back/commit/78faf30ed1be63b009e1763b293ccfabc53f10c4))

* added test + handle_exception function ([`8f17937`](https://github.com/Geode-solutions/OpenGeodeWeb-Back/commit/8f17937dd05581ae9b6818b5a3a04abb1b95785f))

* ([`dca962e`](https://github.com/Geode-solutions/OpenGeodeWeb-Back/commit/dca962e5b0aed0366fa53ebe5ea074c9b3a65de6))


## v4.1.1 (2024-05-03)

### Unknown
Expand Down
24 changes: 11 additions & 13 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@
import flask_cors
from werkzeug.exceptions import HTTPException

from werkzeug.exceptions import HTTPException

from src.opengeodeweb_back.routes import blueprint_routes
from src.opengeodeweb_back.geode_functions import handle_exception


""" Global config """
Expand Down Expand Up @@ -36,17 +35,16 @@


@app.errorhandler(HTTPException)
def handle_exception(e):
response = e.get_response()
response.data = flask.json.dumps(
{
"code": e.code,
"name": e.name,
"description": e.description,
}
)
response.content_type = "application/json"
return response
def errorhandler(e):
return handle_exception(e)


@app.route(
"/error",
methods=["POST"],
)
def return_error():
flask.abort(500, f"Test")


# ''' Main '''
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "OpenGeodeWeb-Back"
version = "4.1.1"
version = "4.2.0-rc.1"
dynamic = ["dependencies"]
authors = [
{ name="Geode-solutions", email="[email protected]" },
Expand Down
4 changes: 3 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# This file is autogenerated by pip-compile with Python 3.11
# This file is autogenerated by pip-compile with Python 3.10
# by the following command:
#
# pip-compile requirements.in
Expand Down Expand Up @@ -110,6 +110,8 @@ rpds-py==0.18.0
# via
# jsonschema
# referencing
typing-extensions==4.12.0
# via asgiref
werkzeug==3.0.2
# via
# -r requirements.in
Expand Down
13 changes: 13 additions & 0 deletions src/opengeodeweb_back/geode_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -354,3 +354,16 @@ def send_file(upload_folder, saved_files, new_file_name):
response.headers["Access-Control-Expose-Headers"] = "new-file-name"

return response


def handle_exception(e):
response = e.get_response()
response.data = flask.json.dumps(
{
"code": e.code,
"name": e.name,
"description": e.description,
}
)
response.content_type = "application/json"
return response
2 changes: 1 addition & 1 deletion src/opengeodeweb_back/routes/blueprint_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def allowed_files():
extensions = geode_functions.list_input_extensions(
flask.request.json["supported_feature"]
)
return {"status": 200, "extensions": extensions}
return flask.make_response({"extensions": extensions}, 200)


with open(
Expand Down
11 changes: 11 additions & 0 deletions tests/test_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,3 +329,14 @@ def test_extension_from_filename():
extension = geode_functions.extension_from_filename("test.toto")
assert type(extension) is str
assert extension.count(".") == 0


def test_handle_exception(client):
route = "/error"
response = client.post(route)
assert response.status_code == 500
data = response.get_json()
assert type(data) is dict
assert type(data["description"]) is str
assert type(data["name"]) is str
assert type(data["code"]) is int

0 comments on commit 5520ba3

Please sign in to comment.