Skip to content

Commit

Permalink
Merge pull request #674 from geekygirlsarah/main
Browse files Browse the repository at this point in the history
Attempt 500 server error fix
  • Loading branch information
geekygirlsarah authored Aug 13, 2023
2 parents c955937 + 8627027 commit 5273d16
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 6 deletions.
4 changes: 3 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@ COPY requirements.txt /code/
RUN pip install --no-cache-dir -r requirements.txt
COPY . .
EXPOSE 8000
CMD python manage.py migrate && python manage.py runserver 0.0.0.0:8000
CMD python manage.py migrate && \
python manage.py collectstatic --clear --no-input && \
python manage.py runserver 0.0.0.0:8000
2 changes: 1 addition & 1 deletion runtime.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
python-3.10.8
python-3.11.4
9 changes: 9 additions & 0 deletions web/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,15 @@ def test_about_view_GET(self):
self.assertTemplateUsed(response, 'about.html')
self.assertTemplateUsed(response, 'base.html')

def test_invalid_page_gives_404_error(self):
url = 'no_real_page'
response = self.client.get(url)

self.assertEqual(response.status_code, 404)
self.assertTemplateUsed(response, 'error404.html')
self.assertTemplateUsed(response, 'base.html')
self.assertTemplateNotUsed(response, 'concepts.html')

def test_compare_concepts_view_both_valid_languages(self):
"""test if compare with 2 valid languages uses the correct templates"""
url = reverse('index') + \
Expand Down
12 changes: 8 additions & 4 deletions web/views.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""codethesaur.us views"""
import json
import logging
import random
import os

Expand Down Expand Up @@ -228,7 +228,7 @@ def render_concepts(request, languages, structure, all_categories):
return render(request, 'concepts.html', response)


def error_handler_400_bad_request(request, _exception):
def error_handler_400_bad_request(request, exception):
"""
Renders the page for a generic client error (HTTP 400)
Expand All @@ -238,11 +238,12 @@ def error_handler_400_bad_request(request, _exception):
"""
store_url_info(request)

logging.error(exception)
response = render(request, 'error400.html')
return HttpResponseBadRequest(response)


def error_handler_403_forbidden(request, _exception):
def error_handler_403_forbidden(request, exception):
"""
Renders the page for a forbidden error (HTTP 403)
Expand All @@ -252,11 +253,12 @@ def error_handler_403_forbidden(request, _exception):
"""
store_url_info(request)

logging.error(exception)
response = render(request, 'error403.html')
return HttpResponseForbidden(response)


def error_handler_404_not_found(request, _exception):
def error_handler_404_not_found(request, exception):
"""
Renders the page for a file not found error (HTTP 404)
Expand All @@ -266,6 +268,7 @@ def error_handler_404_not_found(request, _exception):
"""
store_url_info(request)

logging.info(request)
response = render(request, 'error404.html')
return HttpResponseNotFound(response)

Expand All @@ -279,6 +282,7 @@ def error_handler_500_server_error(request):
"""
store_url_info(request)

logging.error(request)
response = render(request, 'error500.html')
return HttpResponseServerError(response)

Expand Down

0 comments on commit 5273d16

Please sign in to comment.