Skip to content

Commit

Permalink
docs(ajax): improve comments documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
maxpatiiuk committed Jul 25, 2024
1 parent 6939172 commit 9faedc7
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions specifyweb/frontend/js_src/lib/utils/ajax/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ export type AjaxMethod =
| 'POST'
| 'PUT';

/**
* These methods usually don't modify data, so if they fail it is not a big
* deal. If on the other than POST, PUT, DELETE, or PATCH request fails, it
* may cause data loss or data corruption
*/
const safeMethods: ReadonlySet<AjaxMethod> = new Set([
'OPTIONS',
'GET',
Expand Down Expand Up @@ -75,16 +80,13 @@ export type AjaxProps = Omit<RequestInit, 'body' | 'headers' | 'method'> & {
/**
* All front-end network requests should go through this utility.
*
* Wraps native fetch in useful helpers
* It is intended as a replacement for jQuery's ajax
*
* @remarks
* Automatically adds CSRF token to non GET requests
* Casts response to correct typescript type
* Parsers JSON and XML responses
* Handlers errors (including permission errors)
* Wraps native fetch in useful helpers:
* - Automatically adds CSRF token to non GET requests
* - Casts response to correct typescript type
* - Parses JSON and XML responses
* - Handlers errors (including permission errors)
* - Helps with request mocking in tests
*/
// "errorMode" is optional for "GET" requests
export async function ajax<RESPONSE_TYPE = string>(
url: string,
/** These options are passed directly to fetch() */
Expand Down

0 comments on commit 9faedc7

Please sign in to comment.