5htp-core 0.5.1-6 → 0.5.1-7
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.
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "5htp-core",
|
|
3
3
|
"description": "Convenient TypeScript framework designed for Performance and Productivity.",
|
|
4
|
-
"version": "0.5.1-
|
|
4
|
+
"version": "0.5.1-7",
|
|
5
5
|
"author": "Gaetan Le Gac (https://github.com/gaetanlegac)",
|
|
6
6
|
"repository": "git://github.com/gaetanlegac/5htp-core.git",
|
|
7
7
|
"license": "MIT",
|
|
@@ -154,6 +154,27 @@ export class AuthRequired extends CoreError {
|
|
|
154
154
|
public static msgDefaut = "Please Login to Continue.";
|
|
155
155
|
}
|
|
156
156
|
|
|
157
|
+
export class UpgradeRequired extends CoreError {
|
|
158
|
+
public http = 402;
|
|
159
|
+
public title = "Upgrade Required";
|
|
160
|
+
public static msgDefaut = "Please Upgrade to Continue.";
|
|
161
|
+
|
|
162
|
+
public constructor(
|
|
163
|
+
message: string,
|
|
164
|
+
public feature: string,
|
|
165
|
+
details?: TErrorDetails
|
|
166
|
+
) {
|
|
167
|
+
super(message, details);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
public json(): TJsonError & { feature: string } {
|
|
171
|
+
return {
|
|
172
|
+
...super.json(),
|
|
173
|
+
feature: this.feature,
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
|
|
157
178
|
export class Forbidden extends CoreError {
|
|
158
179
|
public http = 403;
|
|
159
180
|
public title = "Access Denied";
|
|
@@ -235,6 +256,8 @@ export const fromJson = ({ code, message, ...details }: TJsonError) => {
|
|
|
235
256
|
|
|
236
257
|
case 401: return new AuthRequired( message, details );
|
|
237
258
|
|
|
259
|
+
case 402: return new UpgradeRequired( message, details.feature, details );
|
|
260
|
+
|
|
238
261
|
case 403: return new Forbidden( message, details );
|
|
239
262
|
|
|
240
263
|
case 404: return new NotFound( message, details );
|
|
@@ -583,11 +583,8 @@ declare type Routes = {
|
|
|
583
583
|
private async handleError( e: CoreError, request: ServerRequest<ServerRouter> ) {
|
|
584
584
|
|
|
585
585
|
const code = 'http' in e ? e.http : 500;
|
|
586
|
-
const route = this.errors[code];
|
|
587
|
-
if (route === undefined)
|
|
588
|
-
throw new Error(`No route for error code ${code}`);
|
|
589
586
|
|
|
590
|
-
const response = new ServerResponse(request).status(code)
|
|
587
|
+
const response = new ServerResponse(request).status(code)
|
|
591
588
|
|
|
592
589
|
// Rapport / debug
|
|
593
590
|
if (code === 500) {
|
|
@@ -613,10 +610,16 @@ declare type Routes = {
|
|
|
613
610
|
|
|
614
611
|
// Return error based on the request format
|
|
615
612
|
if (request.accepts("html")) {
|
|
613
|
+
|
|
614
|
+
const route = this.errors[code];
|
|
615
|
+
if (route === undefined)
|
|
616
|
+
throw new Error(`No route for error code ${code}`);
|
|
617
|
+
|
|
616
618
|
const jsonError = errorToJson(e);
|
|
617
|
-
await response.runController(route, {
|
|
619
|
+
await response.setRoute(route).runController(route, {
|
|
618
620
|
error: jsonError
|
|
619
621
|
});
|
|
622
|
+
|
|
620
623
|
} else if (request.accepts("json")) {
|
|
621
624
|
const jsonError = errorToJson(e);
|
|
622
625
|
await response.json(jsonError);
|