@mcma/api
Advanced tools
Comparing version 0.13.29 to 0.14.0
@@ -196,2 +196,1 @@ "use strict"; | ||
exports.getStatusError = getStatusError; | ||
; |
@@ -35,3 +35,7 @@ "use strict"; | ||
response.statusCode = http_statuses_1.HttpStatusCode.BadRequest; | ||
response.body = new mcma_api_error_1.McmaApiError(response.statusCode, error.message, request.path); | ||
response.body = new mcma_api_error_1.McmaApiError({ | ||
status: response.statusCode, | ||
message: error.message, | ||
path: request.path | ||
}); | ||
requestBodyOK = false; | ||
@@ -60,3 +64,7 @@ } | ||
response.headers = getDefaultResponseHeaders(); | ||
response.body = new mcma_api_error_1.McmaApiError(response.statusCode, "Resource not found on path '" + request.path + "'.", request.path); | ||
response.body = new mcma_api_error_1.McmaApiError({ | ||
status: response.statusCode, | ||
message: "Resource not found on path '" + request.path + "'.", | ||
path: request.path | ||
}); | ||
} | ||
@@ -100,8 +108,17 @@ else if (!methodMatched) { | ||
response.headers["Allow"] = methodsAllowed; | ||
response.body = new mcma_api_error_1.McmaApiError(response.statusCode, "Method '" + request.httpMethod + "' not allowed on path '" + request.path + "'.", request.path); | ||
response.body = new mcma_api_error_1.McmaApiError({ | ||
status: response.statusCode, | ||
message: "Method '" + request.httpMethod + "' not allowed on path '" + request.path + "'.", | ||
path: request.path | ||
}); | ||
} | ||
} | ||
else if ((response.statusCode / 200 << 0) * 200 === 400) { | ||
response.headers = getDefaultResponseHeaders(); | ||
response.body = new mcma_api_error_1.McmaApiError(response.statusCode, response.statusMessage, request.path); | ||
if (!response.body) { | ||
response.body = new mcma_api_error_1.McmaApiError({ | ||
status: response.statusCode, | ||
message: response.errorMessage, | ||
path: request.path | ||
}); | ||
} | ||
} | ||
@@ -118,3 +135,7 @@ else if (response.statusCode === 0) { | ||
response.headers = getDefaultResponseHeaders(); | ||
response.body = new mcma_api_error_1.McmaApiError(response.statusCode, error.message, request.path); | ||
response.body = new mcma_api_error_1.McmaApiError({ | ||
status: response.statusCode, | ||
message: error.message, | ||
path: request.path | ||
}); | ||
} | ||
@@ -121,0 +142,0 @@ } |
@@ -1,9 +0,16 @@ | ||
import { McmaObject } from "@mcma/core"; | ||
export declare class McmaApiError extends McmaObject { | ||
import { McmaObject, McmaObjectProperties } from "@mcma/core"; | ||
export interface McmaApiErrorProperties extends McmaObjectProperties { | ||
timestamp?: Date; | ||
status: number; | ||
message: string; | ||
error?: string; | ||
path: string; | ||
message?: string; | ||
} | ||
export declare class McmaApiError extends McmaObject implements McmaApiErrorProperties { | ||
timestamp: Date; | ||
status: number; | ||
error: string; | ||
constructor(status: number, message: string, path: string); | ||
path: string; | ||
message?: string; | ||
constructor(properties: McmaApiErrorProperties); | ||
} |
@@ -7,11 +7,16 @@ "use strict"; | ||
class McmaApiError extends core_1.McmaObject { | ||
constructor(status, message, path) { | ||
super("ApiError", {}); | ||
this.status = status; | ||
this.message = message; | ||
this.path = path; | ||
this.timestamp = new Date(); | ||
this.error = http_statuses_1.getStatusError(this.status); | ||
constructor(properties) { | ||
super("ApiError", properties); | ||
this.checkProperty("status", "number", true); | ||
this.checkProperty("path", "string", true); | ||
this.checkProperty("message", "string", false); | ||
this.timestamp = this.ensureValidDateOrUndefined(this.timestamp); | ||
if (!this.timestamp) { | ||
this.timestamp = new Date(); | ||
} | ||
if (!this.error) { | ||
this.error = http_statuses_1.getStatusError(this.status); | ||
} | ||
} | ||
} | ||
exports.McmaApiError = McmaApiError; |
@@ -12,6 +12,6 @@ import { ConfigVariables, Logger, LoggerProvider, McmaResource, McmaTracker } from "@mcma/core"; | ||
getRequestBody<T = any>(): T; | ||
setResponseStatusCode(statusCode: number, statusMessage?: string): void; | ||
setResponseBody(body: any): void; | ||
setResponseResourceCreated(resource: McmaResource): void; | ||
setResponseError(code: number, message?: string): void; | ||
setResponseBadRequestDueToMissingBody(): void; | ||
setResponseResourceCreated(resource: McmaResource): void; | ||
setResponseResourceNotFound(): void; | ||
@@ -18,0 +18,0 @@ getTracker(): McmaTracker | undefined; |
@@ -21,19 +21,22 @@ "use strict"; | ||
} | ||
setResponseStatusCode(statusCode, statusMessage) { | ||
this.response.statusCode = statusCode; | ||
this.response.statusMessage = statusMessage; | ||
} | ||
setResponseBody(body) { | ||
this.response.body = body; | ||
} | ||
setResponseBadRequestDueToMissingBody() { | ||
this.setResponseStatusCode(http_statuses_1.HttpStatusCode.BadRequest, "Missing request body."); | ||
} | ||
setResponseResourceCreated(resource) { | ||
this.response.headers["Location"] = resource.id; | ||
this.setResponseStatusCode(http_statuses_1.HttpStatusCode.Created); | ||
this.setResponseBody(resource); | ||
this.response.statusCode = http_statuses_1.HttpStatusCode.Created; | ||
this.response.body = resource; | ||
} | ||
setResponseError(code, message) { | ||
if (code < 400 || code > 599) { | ||
throw new core_1.McmaException("McmaApiRequestContext.setResponseError can only be used to handle 4xx or 5xx errors"); | ||
} | ||
this.response.statusCode = code; | ||
this.response.errorMessage = message; | ||
} | ||
setResponseBadRequestDueToMissingBody() { | ||
this.setResponseError(http_statuses_1.HttpStatusCode.BadRequest, "Missing request body."); | ||
} | ||
setResponseResourceNotFound() { | ||
this.setResponseStatusCode(http_statuses_1.HttpStatusCode.NotFound, "No resource found on path '" + this.request.path + "'."); | ||
this.setResponseError(http_statuses_1.HttpStatusCode.NotFound, "No resource found on path '" + this.request.path + "'."); | ||
} | ||
@@ -40,0 +43,0 @@ getTracker() { |
export declare class McmaApiResponse { | ||
statusCode: number; | ||
statusMessage: string; | ||
errorMessage: string; | ||
headers: { | ||
@@ -5,0 +5,0 @@ [key: string]: string; |
@@ -7,3 +7,3 @@ "use strict"; | ||
this.statusCode = 0; | ||
this.statusMessage = null; | ||
this.errorMessage = null; | ||
this.headers = {}; | ||
@@ -10,0 +10,0 @@ } |
@@ -49,3 +49,3 @@ "use strict"; | ||
jobAssignment.status === core_1.JobStatus.Canceled) { | ||
requestContext.setResponseStatusCode(http_1.HttpStatusCode.Conflict, "JobAssignment is already in a final state"); | ||
requestContext.setResponseError(http_1.HttpStatusCode.Conflict, "JobAssignment is already in a final state"); | ||
return; | ||
@@ -52,0 +52,0 @@ } |
{ | ||
"name": "@mcma/api", | ||
"version": "0.13.29", | ||
"version": "0.14.0", | ||
"description": "Node module for building APIs based on the EBU MCMA framework", | ||
@@ -40,12 +40,12 @@ "engines": { | ||
"peerDependencies": { | ||
"@mcma/client": "0.13.29", | ||
"@mcma/core": "0.13.29", | ||
"@mcma/data": "0.13.29", | ||
"@mcma/worker-invoker": "0.13.29" | ||
"@mcma/client": "0.14.0", | ||
"@mcma/core": "0.14.0", | ||
"@mcma/data": "0.14.0", | ||
"@mcma/worker-invoker": "0.14.0" | ||
}, | ||
"devDependencies": { | ||
"@mcma/client": "0.13.29", | ||
"@mcma/core": "0.13.29", | ||
"@mcma/data": "0.13.29", | ||
"@mcma/worker-invoker": "0.13.29", | ||
"@mcma/client": "0.14.0", | ||
"@mcma/core": "0.14.0", | ||
"@mcma/data": "0.14.0", | ||
"@mcma/worker-invoker": "0.14.0", | ||
"@types/node": "^14.17.22", | ||
@@ -52,0 +52,0 @@ "@types/pluralize": "0.0.29", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
61220
1279