Skip to content

Commit 21fa894

Browse files
committed
Rename applyErrorMappingToFormFromUnprocessableEntityResponseResponse
1 parent 79fb015 commit 21fa894

File tree

4 files changed

+19
-5
lines changed

4 files changed

+19
-5
lines changed

jsdoc.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ module.exports = {
55
"source": {
66
"include": [
77
"src",
8+
"src/plugins",
89
"README.md"
910
],
1011
}

src/plugins/mrujs.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
1-
import {applyErrorMappingToFormFromEntityResponseResponse} from '../request-processing.js'
1+
import {applyErrorMappingToFormFromUnprocessableEntityResponseResponse} from '../request-processing.js'
22

3+
/**
4+
* Calls {@link applyErrorMappingToFormFromUnprocessableEntityResponseResponse}, passing along the
5+
* `element` and `response` from the given `event`
6+
* @param {Event} event - The event that was fired for a fetch response, ideally `ajax:response:error`
7+
* @param {FormElement} event.detail.element - The `form` event that triggered the event
8+
* @param {Response} event.detail.response - The `Response` from the fetch request
9+
*/
310
export async function unprocessableEntityResponseHandler(event) {
4-
await applyErrorMappingToFormFromEntityResponseResponse(event.detail.element, event.detail.response)
11+
await applyErrorMappingToFormFromUnprocessableEntityResponseResponse(event.detail.element, event.detail.response)
512
}

src/request-processing.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
import { applyErrorMappingToForm } from './error-mapping.js'
22

3-
export async function applyErrorMappingToFormFromEntityResponseResponse(form, response) {
3+
/**
4+
* Calls {@link applyErrorMappingToForm}, If the given `response` has a `status` of `422`
5+
* `element` and `response` from the given `event`
6+
* @param {FormElement} form - The `form` event that triggered the event
7+
* @param {Response} response - The `Response` from the fetch request
8+
*/
9+
export async function applyErrorMappingToFormFromUnprocessableEntityResponseResponse(form, response) {
410
if(response.status != 422){ return }
511
const errors = await response.json()
612
applyErrorMappingToForm(form, errors)

test/request-processing.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff 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.applyErrorMappingToFormFromEntityResponseResponse(form, response)
46+
await RequestProcessing.applyErrorMappingToFormFromUnprocessableEntityResponseResponse(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.applyErrorMappingToFormFromEntityResponseResponse(form, response)
90+
await RequestProcessing.applyErrorMappingToFormFromUnprocessableEntityResponseResponse(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)

0 commit comments

Comments
 (0)