UNPKG

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