From 4e5f931c044f1e9f2edbea6b15d0e2b230c08e27 Mon Sep 17 00:00:00 2001 From: "Daniel J. Summers" Date: Sat, 12 Dec 2020 14:37:49 -0500 Subject: [PATCH] Send no content if no profile exists --- src/JobsJobsJobs.Api/Handlers.fs | 2 +- src/jobs-jobs-jobs/src/api/index.ts | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/JobsJobsJobs.Api/Handlers.fs b/src/JobsJobsJobs.Api/Handlers.fs index b7ea4e7..56aadad 100644 --- a/src/JobsJobsJobs.Api/Handlers.fs +++ b/src/JobsJobsJobs.Api/Handlers.fs @@ -134,7 +134,7 @@ module Profile = | Ok citId -> match! Profiles.tryFind citId with | Ok (Some profile) -> return! json profile ctx - | Ok None -> return! Error.notFound ctx + | Ok None -> return! Successful.NO_CONTENT ctx | Error exn -> return! Error.error exn "Cannot retrieve profile" ctx | Error _ -> return! Error.notFound ctx } diff --git a/src/jobs-jobs-jobs/src/api/index.ts b/src/jobs-jobs-jobs/src/api/index.ts index 41b020f..e7a0bf9 100644 --- a/src/jobs-jobs-jobs/src/api/index.ts +++ b/src/jobs-jobs-jobs/src/api/index.ts @@ -14,6 +14,9 @@ const API_URL = `${location.protocol}//${location.host}/api` /** Local storage key for the Jobs, Jobs, Jobs access token */ const JJJ_TOKEN = 'jjj-token' +/** HTTP status for "No Content"; used by the API to indicate a valid query with no results vs. 404 (invalid URL) */ +const NO_CONTENT = 204 + /** * A holder for the JSON Web Token (JWT) returned from Jobs, Jobs, Jobs */ @@ -65,7 +68,7 @@ export async function doRequest(url: string, method?: string, payload?: string) if (method === 'POST' && payload) options.body = payload const actualUrl = (options.method === 'GET' && payload) ? `url?${payload}` : url const resp = await fetch(actualUrl, options) - if (resp.ok || resp.status === 404) return resp + if (resp.ok) return resp throw new Error(`Error executing API request: ${resp.status} ~ ${resp.statusText}`) } @@ -89,7 +92,7 @@ export async function jjjAuthorize(nasToken: string): Promise { */ export async function userProfile(): Promise { const resp = await doRequest(`${API_URL}/profile`) - if (resp.status === 404) { + if (resp.status === NO_CONTENT) { return undefined } const profile = await resp.json()