File tree Expand file tree Collapse file tree 4 files changed +10
-10
lines changed
Expand file tree Collapse file tree 4 files changed +10
-10
lines changed Original file line number Diff line number Diff line change @@ -191,13 +191,13 @@ We use the `aria-describedby` so that your markup is **accessible by default**.
191191Since each application has different needs, the best way to utilize the custom elements that wrap around a form to provide event handlers is to subclass them to make your own versions:
192192
193193``` js
194- import { applyErrorMappingToFormFromUnprocessableEntityResponseResponse } from ' @practical-computer/error-handling/request-processing'
194+ import { applyErrorMappingFromResponse } from ' @practical-computer/error-handling/request-processing'
195195
196196class AppErrorHandlingElement extends ErrorHandlingElement {
197197 connectedCallback () {
198198 super .connectedCallback ()
199199
200- this .addEventListener (` custom-fetch-library:request-error` , applyErrorMappingToFormFromUnprocessableEntityResponseResponse )
200+ this .addEventListener (` custom-fetch-library:request-error` , applyErrorMappingFromResponse )
201201
202202 this .form .addEventListener (` submit` , (event ) => {
203203 if (! event .defaultPrevented ){
@@ -234,12 +234,12 @@ The provided request processing functions expect a `422` response to indicate th
234234### Using the basic request processing function
235235
236236```js
237- import { applyErrorMappingToFormFromUnprocessableEntityResponseResponse } from '@practical-computer/error-handling/request-processing'
237+ import { applyErrorMappingFromResponse } from '@practical-computer/error-handling/request-processing'
238238
239239const response = fetch (... )
240240const form = // ...
241241
242- applyErrorMappingToFormFromUnprocessableEntityResponseResponse (form, response)
242+ applyErrorMappingFromResponse (form, response)
243243````
244244
245245#### Loading the Mrujs plugin
Original file line number Diff line number Diff line change 1- import { applyErrorMappingToFormFromUnprocessableEntityResponseResponse } from '../request-processing.js'
1+ import { applyErrorMappingFromResponse } from '../request-processing.js'
22
33/**
4- * Calls {@link applyErrorMappingToFormFromUnprocessableEntityResponseResponse }, passing along the
4+ * Calls {@link applyErrorMappingFromResponse }, passing along the
55 * `element` and `response` from the given `event`
66 * @param {Event } event - The event that was fired for a fetch response, ideally `ajax:response:error`
77 * @param {FormElement } event.detail.element - The `form` event that triggered the event
88 * @param {Response } event.detail.response - The `Response` from the fetch request
99 */
1010export async function unprocessableEntityResponseHandler ( event ) {
11- await applyErrorMappingToFormFromUnprocessableEntityResponseResponse ( event . detail . element , event . detail . response )
11+ await applyErrorMappingFromResponse ( event . detail . element , event . detail . response )
1212}
Original file line number Diff line number Diff line change @@ -6,7 +6,7 @@ import { applyErrorMappingToForm } from './error-mapping.js'
66 * @param {FormElement } form - The `form` event that triggered the event
77 * @param {Response } response - The `Response` from the fetch request
88 */
9- export async function applyErrorMappingToFormFromUnprocessableEntityResponseResponse ( form , response ) {
9+ export async function applyErrorMappingFromResponse ( form , response ) {
1010 if ( response . status != 422 ) { return }
1111 const errors = await response . json ( )
1212 applyErrorMappingToForm ( form , errors )
Original file line number Diff line number Diff line change @@ -43,7 +43,7 @@ suite('Request Processing', async () => {
4343
4444 const response = new Response ( JSON . stringify ( errors ) , { status : 400 } )
4545
46- await RequestProcessing . applyErrorMappingToFormFromUnprocessableEntityResponseResponse ( form , response )
46+ await RequestProcessing . applyErrorMappingFromResponse ( form , response )
4747
4848 assert . equal ( 2 , form . querySelectorAll ( `[data-error-type]` ) . length )
4949 } )
@@ -87,7 +87,7 @@ suite('Request Processing', async () => {
8787
8888 const response = new Response ( JSON . stringify ( errors ) , { status : 422 } )
8989
90- await RequestProcessing . applyErrorMappingToFormFromUnprocessableEntityResponseResponse ( form , response )
90+ await RequestProcessing . applyErrorMappingFromResponse ( form , response )
9191
9292 assert . equal ( 1 , form . querySelectorAll ( `[data-error-type]` ) . length )
9393 assert . equal ( 1 , form . querySelectorAll ( `[data-error-type][data-error-type="ad_hoc_server_error_1"]` ) . length )
You can’t perform that action at this time.
0 commit comments