« get me outta code hell

Set HTTP status codes on 404, etc - scratchrlol - Simple HTML-based Scratch client
summary refs log tree commit diff
diff options
context:
space:
mode:
authorFlorrie <towerofnix@gmail.com>2018-11-14 22:57:24 -0400
committerFlorrie <towerofnix@gmail.com>2018-11-14 22:57:24 -0400
commitffd70884e61f5baa52fc2b84dfcc812ea66cf783 (patch)
tree6d57df58d450e0e7cad7cbd963cc4676740e23f7
parentac850d37e7964edaf4ea69aac8a5dfe0c49fca09 (diff)
Set HTTP status codes on 404, etc
-rwxr-xr-xindex.js4
1 files changed, 4 insertions, 0 deletions
diff --git a/index.js b/index.js
index 3ed4996..53426f5 100755
--- a/index.js
+++ b/index.js
@@ -367,6 +367,7 @@ const handleRequest = async (request, response) => {
 
     const project = await getProject(projectID, cookie.token)
     if (project.code === 'NotFound') {
+      response.statusCode = 404
       return page(request, response, fixWS`
         404. Sorry, that project either doesn't exist or isn't shared.
       `)
@@ -425,6 +426,7 @@ const handleRequest = async (request, response) => {
     const user = await getUser(username)
 
     if (user.code === 'NotFound') {
+      response.statusCode = 404
       return page(request, response, fixWS`
         404. Sorry, that user doesn't exist.
       `)
@@ -478,6 +480,7 @@ const handleRequest = async (request, response) => {
     `)
   }
 
+  response.statusCode = 404
   return page(request, response, fixWS`
     404. Sorry, I'm not sure where you are right now.
   `)
@@ -486,6 +489,7 @@ const handleRequest = async (request, response) => {
 const server = http.createServer((request, response) => {
   handleRequest(request, response).catch(error => {
     console.error(error)
+    response.statusCode = 500
     return page(request, response, fixWS`
       500. Sorry, there was an internal server error.
     `)