From a6fed0acbdf57e1a70897448ae7e62a0cab841c5 Mon Sep 17 00:00:00 2001 From: Dmitry Molotkov Date: Fri, 30 Nov 2018 22:15:29 +0300 Subject: [PATCH] fix(vue-app): allow passing custom props to error function (#4462) Resolves #4460. --- packages/vue-app/template/utils.js | 1 + test/e2e/basic.browser.test.js | 2 +- test/fixtures/basic/pages/error2.vue | 2 +- test/unit/basic.ssr.test.js | 1 + 4 files changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/vue-app/template/utils.js b/packages/vue-app/template/utils.js index 066400915c..faab985b4e 100644 --- a/packages/vue-app/template/utils.js +++ b/packages/vue-app/template/utils.js @@ -285,6 +285,7 @@ export function normalizeError(err) { message = err.message || err } return { + ...err, message: message, statusCode: (err.statusCode || err.status || (err.response && err.response.status) || 500) } diff --git a/test/e2e/basic.browser.test.js b/test/e2e/basic.browser.test.js index 35029bb727..5433a464e8 100644 --- a/test/e2e/basic.browser.test.js +++ b/test/e2e/basic.browser.test.js @@ -166,7 +166,7 @@ describe('basic browser', () => { await page.nuxt.navigate('/error2') expect(await page.$text('.title')).toBe('Custom error') - expect(await page.nuxt.errorData()).toEqual({ message: 'Custom error', statusCode: 500 }) + expect(await page.nuxt.errorData()).toEqual({ message: 'Custom error', statusCode: 500, customProp: 'ezpz' }) }) test('/redirect-middleware', async () => { diff --git a/test/fixtures/basic/pages/error2.vue b/test/fixtures/basic/pages/error2.vue index 252ad842a4..8c97235635 100644 --- a/test/fixtures/basic/pages/error2.vue +++ b/test/fixtures/basic/pages/error2.vue @@ -5,7 +5,7 @@ diff --git a/test/unit/basic.ssr.test.js b/test/unit/basic.ssr.test.js index cffb39a864..dd716052bd 100644 --- a/test/unit/basic.ssr.test.js +++ b/test/unit/basic.ssr.test.js @@ -235,6 +235,7 @@ describe('basic ssr', () => { expect(html).toContain('Custom error') expect(error.message).toContain('Custom error') expect(error.statusCode).toBe(500) + expect(error.customProp).toBe('ezpz') }) test('/error2 status code', async () => {