E
E
Eugene2021-11-17 21:15:50
Vue.js
Eugene, 2021-11-17 21:15:50

How to show error page on condition after validation in middleware?

I can’t understand a little how middleware works in NUXT.
Namely, after checking, for example, how can I show the error page (which I have in layouts\error.vue), passing it to error -> statusCode?

I see from the examples that everyone does only a redirect.

Now I have some kind of nonsense. I store the http code in the store and use it to display content (200 - successful, or other types of errors) and in the middleware, if the check fails, I change the store to 4 ** code.
But somehow it doesn't seem right to me.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
W
WapSter, 2021-11-17
@wapster92

class CustomError extends Error {
   constructor(message, statusCode) {
    super(message);
    this.statusCode = statusCode;
  }
}
throw CustomError('Страница не найдена, '404')

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question