1 | # Experimental syntax proposal
|
2 |
|
3 | ```js
|
4 | // Using a factory
|
5 | const ErrorFactory = require('server/error');
|
6 | const ServerError = ErrorFactory('/server/', {});
|
7 |
|
8 | const ErrorFactory = require('server/error');
|
9 | class ServerError extends ErrorFactory {
|
10 | namespace: '/server',
|
11 | url: ({ id }) => ...,
|
12 | status: 500
|
13 | }
|
14 |
|
15 | // Using the plain import method
|
16 | const ServerError = require('server/error')('/server/');
|
17 | const ServerError = require('server/error')('/server/', {
|
18 | namespace: '/server/',
|
19 | url: ({ slug }) => `https://serverjs.io/documentation/errors/#${slug}`,
|
20 | status: 500,
|
21 | });
|
22 | const ServerError = require('server/error')({
|
23 | namespace: '/server/'
|
24 | });
|
25 |
|
26 | const SassError = require('server/error')({
|
27 | namespace: '/plugin/sass',
|
28 | url: ({ slug }) => `https://serverjs.io/documentation/errors/#${slug}`,
|
29 | });
|
30 |
|
31 | const ServerError = require('server/error');
|
32 |
|
33 | const SassError = ServerError(null, {
|
34 | namespace: '/plugin/sass',
|
35 | status: 500
|
36 | });
|
37 |
|
38 | const SassError = ServerError.defaults({
|
39 | namespace: '/plugin/sass/',
|
40 | status: 500
|
41 | });
|
42 |
|
43 | SassError.exists = ({ file }) => `
|
44 | The file "${file}" already exists. Please rename it or remove it so @sass/server
|
45 | can work properly. <3
|
46 | `;
|
47 |
|
48 | throw new SassError('exists');
|
49 | throw new SassError('exists', { status: 500 });
|
50 | throw new SassError('exists', { file: FILENAME });
|
51 | ```
|