@nymphjs/server 1.0.0-beta.2 → 1.0.0-beta.21

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,68 @@
1
+ /**
2
+ * HTTP status code to status text map.
3
+ */
4
+ export const statusDescriptions: { [k: number]: string } = {
5
+ 100: 'Continue',
6
+ 101: 'Switching Protocols',
7
+ 102: 'Processing',
8
+ 103: 'Early Hints',
9
+ 200: 'OK',
10
+ 201: 'Created',
11
+ 202: 'Accepted',
12
+ 203: 'Non-Authoritative Information',
13
+ 204: 'No Content',
14
+ 205: 'Reset Content',
15
+ 206: 'Partial Content',
16
+ 207: 'Multi-Status',
17
+ 208: 'Already Reported',
18
+ 226: 'IM Used',
19
+ 300: 'Multiple Choices',
20
+ 301: 'Moved Permanently',
21
+ 302: 'Found',
22
+ 303: 'See Other',
23
+ 304: 'Not Modified',
24
+ 305: 'Use Proxy',
25
+ 306: 'Switch Proxy',
26
+ 307: 'Temporary Redirect',
27
+ 308: 'Permanent Redirect',
28
+ 400: 'Bad Request',
29
+ 401: 'Unauthorized',
30
+ 402: 'Payment Required',
31
+ 403: 'Forbidden',
32
+ 404: 'Not Found',
33
+ 405: 'Method Not Allowed',
34
+ 406: 'Not Acceptable',
35
+ 407: 'Proxy Authentication Required',
36
+ 408: 'Request Timeout',
37
+ 409: 'Conflict',
38
+ 410: 'Gone',
39
+ 411: 'Length Required',
40
+ 412: 'Precondition Failed',
41
+ 413: 'Payload Too Large',
42
+ 414: 'URI Too Long',
43
+ 415: 'Unsupported Media Type',
44
+ 416: 'Range Not Satisfiable',
45
+ 417: 'Expectation Failed',
46
+ 418: "I'm a teapot",
47
+ 421: 'Misdirected Request',
48
+ 422: 'Unprocessable Entity',
49
+ 423: 'Locked',
50
+ 424: 'Failed Dependency',
51
+ 425: 'Too Early',
52
+ 426: 'Upgrade Required',
53
+ 428: 'Precondition Required',
54
+ 429: 'Too Many Requests',
55
+ 431: 'Request Header Fields Too Large',
56
+ 451: 'Unavailable For Legal Reasons',
57
+ 500: 'Internal Server Error',
58
+ 501: 'Not Implemented',
59
+ 502: 'Bad Gateway',
60
+ 503: 'Service Unavailable',
61
+ 504: 'Gateway Timeout',
62
+ 505: 'HTTP Version Not Supported',
63
+ 506: 'Variant Also Negotiates',
64
+ 507: 'Insufficient Storage',
65
+ 508: 'Loop Detected',
66
+ 510: 'Not Extended',
67
+ 511: 'Network Authentication Required',
68
+ };
@@ -1,6 +1,8 @@
1
1
  import { Entity as EntityServer, EntityInvalidDataError } from '@nymphjs/nymph';
2
2
  import { Entity } from '@nymphjs/client';
3
3
 
4
+ import { HttpError } from './HttpError';
5
+
4
6
  export type EmployeeBaseData<T> = {
5
7
  name?: string;
6
8
  id?: number;
@@ -34,6 +36,8 @@ export class EmployeeModel extends EntityServer<EmployeeModelData> {
34
36
  '$testMethodStateless',
35
37
  '$testMethod',
36
38
  '$throwError',
39
+ '$throwHttpError',
40
+ '$throwHttpErrorWithDescription',
37
41
  ];
38
42
  public static clientEnabledStaticMethods = ['testStatic', 'throwErrorStatic'];
39
43
  protected $protectedTags = ['employee'];
@@ -121,6 +125,14 @@ export class EmployeeModel extends EntityServer<EmployeeModelData> {
121
125
  throw new BadFunctionCallError('This function only throws errors.');
122
126
  }
123
127
 
128
+ public $throwHttpError() {
129
+ throw new HttpError('A 501 HTTP error.', 501);
130
+ }
131
+
132
+ public $throwHttpErrorWithDescription() {
133
+ throw new HttpError('A 512 HTTP error.', 512, 'Some Error');
134
+ }
135
+
124
136
  public static inaccessibleMethod() {
125
137
  return true;
126
138
  }
@@ -169,16 +181,24 @@ export class Employee extends Entity<EmployeeData> {
169
181
  return this.$serverCall('$throwError', []);
170
182
  }
171
183
 
184
+ $throwHttpError() {
185
+ return this.$serverCall('$throwHttpError', []);
186
+ }
187
+
188
+ $throwHttpErrorWithDescription() {
189
+ return this.$serverCall('$throwHttpErrorWithDescription', []);
190
+ }
191
+
172
192
  static testStatic(value: number) {
173
- return Employee.serverCallStatic('testStatic', [value]);
193
+ return this.serverCallStatic('testStatic', [value]);
174
194
  }
175
195
 
176
196
  static throwErrorStatic() {
177
- return Employee.serverCallStatic('throwErrorStatic', []);
197
+ return this.serverCallStatic('throwErrorStatic', []);
178
198
  }
179
199
 
180
200
  static inaccessibleMethod() {
181
- return Employee.serverCallStatic('inaccessibleMethod', []);
201
+ return this.serverCallStatic('inaccessibleMethod', []);
182
202
  }
183
203
  }
184
204