Skip to content
This repository has been archived by the owner on Aug 29, 2018. It is now read-only.

Override default error page #102

Closed
qazs opened this issue Jan 19, 2018 · 5 comments
Closed

Override default error page #102

qazs opened this issue Jan 19, 2018 · 5 comments

Comments

@qazs
Copy link

qazs commented Jan 19, 2018

Is there a way to override the default feathers error page?
Eg. Placing a custom 404.html in /public folder?

@daffl
Copy link
Member

daffl commented Jan 19, 2018

As mentioned in the errorHandler API documentation you can either pass a middleware or a path to an HTML file. I just added an example how to pass files for each error code

const { errorHandler } = require('@feathersjs/express');
const app = feathers();

app.use(errorHandler({
    html: {
      404: 'path/to/notFound.html',
      500: 'there/will/be/robots.html'
    }
}));

@qazs
Copy link
Author

qazs commented Jan 21, 2018

Thanks, I tried your example but I get this error:
TypeError: errorHandler is not a function
Is it something I'm missing?

@daffl
Copy link
Member

daffl commented Jan 21, 2018

Oh yes, sorry it was const { errorHandler } = require('@feathersjs/express');, I fixed it in the examples as well.

@qazs
Copy link
Author

qazs commented Jan 22, 2018

Thanks! I got it to work using the previous code:

const handler = require('feathers-errors/handler');
const notFound = require('feathers-errors/not-found');

app.use(notFound());
app.use(handler({
  html: {
    401: app.get('public') + '/401.html',
    404: app.get('public') + '/404.html'
  }
}));

It's a bit confusing though as there are 2 feathers errors module, @feathers/errors and feathers-errors. I went with the generator code and it's good.

@qazs qazs closed this as completed Jan 22, 2018
@daffl
Copy link
Member

daffl commented Jan 22, 2018

feathers-errors should log a deprecation message when you try to install it with the name change documented in the migration guide.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants