Skip to content

Commit

Permalink
Merge branch 'a4b920a' into feature/jacoblee23/crud-routes
Browse files Browse the repository at this point in the history
  • Loading branch information
JacobLee23 committed Jan 28, 2024
2 parents 6443039 + a4b920a commit 44bf3e8
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions frontend/src/api/requests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ type Method = "GET" | "POST" | "PUT" | "PATCH" | "DELETE";
/**
* Throws an error if the status code of the HTTP response indicates an error. If an HTTP error was
* raised, throws an error.
*
*
* @param response A `Response` object returned by `fetch()`
* @throws An `Error` object if the response status was not successful (2xx) or a redirect (3xx)
*/
Expand All @@ -32,7 +32,7 @@ async function assertOK(response: Response): Promise<void> {

/**
* Wrapper for the `fetch()` function.
*
*
* @param method The HTTP method (see `Method`)
* @param url The URL to request from
* @param body The request body (or undefined, if none)
Expand Down Expand Up @@ -62,7 +62,7 @@ async function fetchRequest(

/**
* Sends a GET request to the indicated API URL.
*
*
* @param url The URL to request from
* @param headers The request headers
* @returns A `Response` object returned by `fetch()`
Expand All @@ -73,7 +73,7 @@ export async function GET(url: string, headers: Record<string, string> = {}): Pr

/**
* Sends a POST request with the provided request body to the indicated API URL.
*
*
* @param url The URL to request from
* @param body The request body (or undefined, if none)
* @param headers The request headers
Expand All @@ -89,7 +89,7 @@ export async function POST(

/**
* Sends a PUT request with the provided request body to the indicated API URL.
*
*
* @param url The URL to request from
* @param body The request body (or undefined, if none)
* @param headers The request headers
Expand All @@ -105,7 +105,7 @@ export async function PUT(

/**
* Sends a PATCH request with the provided request body to the indicated API URL.
*
*
* @param url The URL to request from
* @param body The request body (or undefined, if none)
* @param headers The request headers
Expand All @@ -121,7 +121,7 @@ export async function PATCH(

/**
* Sends a DELETE request with the provided request body to the indicated API URL.
*
*
* @param url The URL to request from
* @param body The request body (or undefined, if none)
* @param headers The request headers
Expand Down Expand Up @@ -149,13 +149,13 @@ export type APIError = { success: false; error: string };
* to perform more straightforward exception-checking without requiring
* extensive `try`-`catch` hadnling, making use of TypeScript's type narrowing
* feature.
*
*
* By checking the value of the `success` field, it can be quickly determined
* whether the `data` field (containing an actual API response) or the `error`
* field (containing an error message) should be accessed.
*
*
* Recommended usage:
*
*
* ```
* if (result.success) {
* console.log(result.data);
Expand All @@ -168,17 +168,17 @@ export type APIResult<T> = APIData<T> | APIError;

/**
* Helper function for API client functions for consistent error handling.
*
*
* Recommended usage:
*
*
* ```
* try {
* ...
* } catch (error) {
* return handleAPIError(error);
* }
* ```
*
*
* @param error The error thrown by a lower-level API function
* @returns An `APIError` object with a message from the given error
*/
Expand Down

0 comments on commit 44bf3e8

Please sign in to comment.