Skip to content

Commit

Permalink
Fix 500 error when session properties are empty
Browse files Browse the repository at this point in the history
Signed-off-by: Ashcon Partovi <ashcon@partovi.net>
  • Loading branch information
Electroid committed May 1, 2020
1 parent 8d0193a commit 27867ef
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
6 changes: 3 additions & 3 deletions src/api.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ export user = (id) ->
return notFound("No user with the UUID '#{id}' was found")
unless history
history = [name: profile.name]
texturesRaw = profile.properties?.filter((item) -> item.name == "textures")[0]
textures = JSON.parse(atob(texturesRaw?.value || btoa("{}"))).textures
texturesRaw = profile.properties?.filter((item) -> item.name == "textures")[0] || {}
textures = JSON.parse(atob(texturesRaw?.value || btoa("{}"))).textures || {}
unless textures.isEmpty()
[skin, cape] = await Promise.all([
buffer(skinUrl) if skinUrl = textures.SKIN?.url,
Expand All @@ -58,7 +58,7 @@ export user = (id) ->
slim: textures.SKIN?.metadata?.model == "slim" || type == "alex"
skin: {url: skinUrl, data: skin}
cape: {url: capeUrl, data: cape} if capeUrl,
raw: {value: texturesRaw.value, signature: texturesRaw.signature}
raw: {value: texturesRaw.value, signature: texturesRaw.signature} unless texturesRaw.isEmpty()
created_at: date
await USERS.put(id, JSON.stringify(response), {expirationTtl: 60 * 5})
respond(response, json: true)
Expand Down
2 changes: 1 addition & 1 deletion src/index.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { error, notFound } from "./http"
import { uuid, user, avatar } from "./api"

addEventListener("fetch", (event) ->
event.respondWith(route(event.request)))
event.respondWith(routeDebug(event.request)))

routeDebug = (request) ->
try
Expand Down

0 comments on commit 27867ef

Please sign in to comment.