Add custom HTTP headers into response error

What problem does this feature solve?

When I throw an error in Nuxt.js, I can only customize statusCode and message properties.
But sometimes I need to add HTTP headers to the response.

So I would like to set a custom header list for the error, eg. Retry-After: 120 (see google recommendation)

What does the proposed changes look like?

Set the Retry-After header on error.

eg. in a page.vue:

export default {
  asyncData () {
    try {
      // ...
    } catch (error) {
      if (error.statusCode === 429) {
        error.headers = { 'Retry-After': 120 }
      throw error

or in a nuxt module:

throw {
  statusCode: 503,
  message: 'Your request timed out. Please retry in a few minutes',
  headers: { 'Retry-After': 120 }

1 possible answer(s) on “Add custom HTTP headers into response error