|
@@ -5,15 +5,15 @@ import {getBody, getDeserializerObjects} from './utils'; |
|
|
import {IncomingMessage, ServerResponse} from 'http'; |
|
|
import {IncomingMessage, ServerResponse} from 'http'; |
|
|
|
|
|
|
|
|
export const handleHasMethodAndUrl: Middleware = ({ |
|
|
export const handleHasMethodAndUrl: Middleware = ({ |
|
|
errorResponseBodyLanguage: [errorLanguageCode, errorMessageCollection], |
|
|
|
|
|
|
|
|
errorResponseBodyLanguage, |
|
|
}) => (req: IncomingMessage, res: ServerResponse) => { |
|
|
}) => (req: IncomingMessage, res: ServerResponse) => { |
|
|
if (!req.method) { |
|
|
if (!req.method) { |
|
|
res.writeHead(constants.HTTP_STATUS_METHOD_NOT_ALLOWED, { |
|
|
res.writeHead(constants.HTTP_STATUS_METHOD_NOT_ALLOWED, { |
|
|
'Allow': 'HEAD, GET, POST, PUT, PATCH, DELETE', |
|
|
'Allow': 'HEAD, GET, POST, PUT, PATCH, DELETE', |
|
|
'Content-Language': errorLanguageCode, |
|
|
|
|
|
|
|
|
'Content-Language': errorResponseBodyLanguage.name, |
|
|
|
|
|
|
|
|
}); |
|
|
}); |
|
|
res.statusMessage = errorMessageCollection.statusMessages.methodNotAllowed(); |
|
|
|
|
|
|
|
|
res.statusMessage = errorResponseBodyLanguage.statusMessages.methodNotAllowed(); |
|
|
res.end(); |
|
|
res.end(); |
|
|
return { |
|
|
return { |
|
|
handled: true |
|
|
handled: true |
|
@@ -22,7 +22,7 @@ export const handleHasMethodAndUrl: Middleware = ({ |
|
|
|
|
|
|
|
|
if (!req.url) { |
|
|
if (!req.url) { |
|
|
res.statusCode = constants.HTTP_STATUS_BAD_REQUEST; |
|
|
res.statusCode = constants.HTTP_STATUS_BAD_REQUEST; |
|
|
res.statusMessage = errorMessageCollection.statusMessages.badRequest(); |
|
|
|
|
|
|
|
|
res.statusMessage = errorResponseBodyLanguage.statusMessages.badRequest(); |
|
|
res.end(); |
|
|
res.end(); |
|
|
return { |
|
|
return { |
|
|
handled: true |
|
|
handled: true |
|
@@ -39,9 +39,9 @@ export const handleGetRoot: Middleware = ({ |
|
|
appParams, |
|
|
appParams, |
|
|
serverParams, |
|
|
serverParams, |
|
|
responseBodyMediaType: [responseBodyMediaType, responseBodySerializerPair], |
|
|
responseBodyMediaType: [responseBodyMediaType, responseBodySerializerPair], |
|
|
responseBodyLanguage: [languageCode, responseBodyMessageCollection], |
|
|
|
|
|
|
|
|
responseBodyLanguage, |
|
|
responseBodyEncoding: [encodingKey, encoding], |
|
|
responseBodyEncoding: [encodingKey, encoding], |
|
|
errorResponseBodyLanguage: [errorLanguageCode, errorMessageCollection], |
|
|
|
|
|
|
|
|
errorResponseBodyLanguage, |
|
|
}) => (_req: IncomingMessage, res: ServerResponse) => { |
|
|
}) => (_req: IncomingMessage, res: ServerResponse) => { |
|
|
const data = { |
|
|
const data = { |
|
|
name: appParams.name |
|
|
name: appParams.name |
|
@@ -52,9 +52,9 @@ export const handleGetRoot: Middleware = ({ |
|
|
serialized = responseBodySerializerPair.serialize(data); |
|
|
serialized = responseBodySerializerPair.serialize(data); |
|
|
} catch { |
|
|
} catch { |
|
|
res.writeHead(constants.HTTP_STATUS_INTERNAL_SERVER_ERROR, { |
|
|
res.writeHead(constants.HTTP_STATUS_INTERNAL_SERVER_ERROR, { |
|
|
'Content-Language': errorLanguageCode, |
|
|
|
|
|
|
|
|
'Content-Language': errorResponseBodyLanguage.name, |
|
|
}); |
|
|
}); |
|
|
res.statusMessage = errorMessageCollection.statusMessages.unableToSerializeResponse(); |
|
|
|
|
|
|
|
|
res.statusMessage = errorResponseBodyLanguage.statusMessages.unableToSerializeResponse(); |
|
|
res.end(); |
|
|
res.end(); |
|
|
return { |
|
|
return { |
|
|
handled: true, |
|
|
handled: true, |
|
@@ -66,9 +66,9 @@ export const handleGetRoot: Middleware = ({ |
|
|
encoded = encoding.encode(serialized); |
|
|
encoded = encoding.encode(serialized); |
|
|
} catch { |
|
|
} catch { |
|
|
res.writeHead(constants.HTTP_STATUS_INTERNAL_SERVER_ERROR, { |
|
|
res.writeHead(constants.HTTP_STATUS_INTERNAL_SERVER_ERROR, { |
|
|
'Content-Language': errorLanguageCode, |
|
|
|
|
|
|
|
|
'Content-Language': errorResponseBodyLanguage.name, |
|
|
}); |
|
|
}); |
|
|
res.statusMessage = errorMessageCollection.statusMessages.unableToEncodeResponse(); |
|
|
|
|
|
|
|
|
res.statusMessage = errorResponseBodyLanguage.statusMessages.unableToEncodeResponse(); |
|
|
res.end(); |
|
|
res.end(); |
|
|
return { |
|
|
return { |
|
|
handled: true, |
|
|
handled: true, |
|
@@ -77,7 +77,7 @@ export const handleGetRoot: Middleware = ({ |
|
|
|
|
|
|
|
|
const theHeaders: Record<string, string> = { |
|
|
const theHeaders: Record<string, string> = { |
|
|
'Content-Type': responseBodyMediaType, |
|
|
'Content-Type': responseBodyMediaType, |
|
|
'Content-Language': languageCode, |
|
|
|
|
|
|
|
|
'Content-Language': responseBodyLanguage.name, |
|
|
'Content-Encoding': encodingKey, |
|
|
'Content-Encoding': encodingKey, |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
@@ -91,14 +91,14 @@ export const handleGetRoot: Middleware = ({ |
|
|
// we are using custom headers for links because the standard Link header |
|
|
// we are using custom headers for links because the standard Link header |
|
|
// is referring to the document metadata (e.g. author, next page, etc) |
|
|
// is referring to the document metadata (e.g. author, next page, etc) |
|
|
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Link |
|
|
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Link |
|
|
theHeaders['X-Resource-Link'] = availableResources |
|
|
|
|
|
|
|
|
theHeaders['Link'] = availableResources |
|
|
.map((r) => |
|
|
.map((r) => |
|
|
`<${serverParams.baseUrl}/${r.state.routeName}>; name="${r.state.collectionName}"`, |
|
|
|
|
|
|
|
|
`<${serverParams.baseUrl}/${r.state.routeName}>; rel="related"; name="${r.state.collectionName}"`, |
|
|
) |
|
|
) |
|
|
.join(', '); |
|
|
.join(', '); |
|
|
} |
|
|
} |
|
|
res.writeHead(constants.HTTP_STATUS_OK, theHeaders); |
|
|
res.writeHead(constants.HTTP_STATUS_OK, theHeaders); |
|
|
res.statusMessage = responseBodyMessageCollection.statusMessages.ok(); |
|
|
|
|
|
|
|
|
res.statusMessage = responseBodyLanguage.statusMessages.ok(); |
|
|
res.end(encoded); |
|
|
res.end(encoded); |
|
|
return { |
|
|
return { |
|
|
handled: true |
|
|
handled: true |
|
@@ -108,9 +108,9 @@ export const handleGetRoot: Middleware = ({ |
|
|
export const handleGetCollection: Middleware = ({ |
|
|
export const handleGetCollection: Middleware = ({ |
|
|
resource, |
|
|
resource, |
|
|
responseBodyMediaType: [responseBodyMediaType, responseBodySerializerPair], |
|
|
responseBodyMediaType: [responseBodyMediaType, responseBodySerializerPair], |
|
|
responseBodyLanguage: [languageCode, responseBodyMessageCollection], |
|
|
|
|
|
|
|
|
responseBodyLanguage, |
|
|
responseBodyEncoding: [encodingKey, encoding], |
|
|
responseBodyEncoding: [encodingKey, encoding], |
|
|
errorResponseBodyLanguage: [errorLanguageCode, errorMessageCollection], |
|
|
|
|
|
|
|
|
errorResponseBodyLanguage, |
|
|
backendState, |
|
|
backendState, |
|
|
query, |
|
|
query, |
|
|
}) => async (_req: IncomingMessage, res: ServerResponse) => { |
|
|
}) => async (_req: IncomingMessage, res: ServerResponse) => { |
|
@@ -118,9 +118,9 @@ export const handleGetCollection: Middleware = ({ |
|
|
await resource.dataSource.initialize(); |
|
|
await resource.dataSource.initialize(); |
|
|
} catch { |
|
|
} catch { |
|
|
res.writeHead(constants.HTTP_STATUS_INTERNAL_SERVER_ERROR, { |
|
|
res.writeHead(constants.HTTP_STATUS_INTERNAL_SERVER_ERROR, { |
|
|
'Content-Language': errorLanguageCode, |
|
|
|
|
|
|
|
|
'Content-Language': errorResponseBodyLanguage.name, |
|
|
}); |
|
|
}); |
|
|
res.statusMessage = errorMessageCollection.statusMessages.unableToInitializeResourceDataSource(resource); |
|
|
|
|
|
|
|
|
res.statusMessage = errorResponseBodyLanguage.statusMessages.unableToInitializeResourceDataSource(resource); |
|
|
res.end(); |
|
|
res.end(); |
|
|
return { |
|
|
return { |
|
|
handled: true |
|
|
handled: true |
|
@@ -137,9 +137,9 @@ export const handleGetCollection: Middleware = ({ |
|
|
} |
|
|
} |
|
|
} catch { |
|
|
} catch { |
|
|
res.writeHead(constants.HTTP_STATUS_INTERNAL_SERVER_ERROR, { |
|
|
res.writeHead(constants.HTTP_STATUS_INTERNAL_SERVER_ERROR, { |
|
|
'Content-Language': errorLanguageCode, |
|
|
|
|
|
|
|
|
'Content-Language': errorResponseBodyLanguage.name, |
|
|
}); |
|
|
}); |
|
|
res.statusMessage = errorMessageCollection.statusMessages.unableToFetchResourceCollection(resource); |
|
|
|
|
|
|
|
|
res.statusMessage = errorResponseBodyLanguage.statusMessages.unableToFetchResourceCollection(resource); |
|
|
res.end(); |
|
|
res.end(); |
|
|
return { |
|
|
return { |
|
|
handled: true |
|
|
handled: true |
|
@@ -151,9 +151,9 @@ export const handleGetCollection: Middleware = ({ |
|
|
serialized = responseBodySerializerPair.serialize(data); |
|
|
serialized = responseBodySerializerPair.serialize(data); |
|
|
} catch { |
|
|
} catch { |
|
|
res.writeHead(constants.HTTP_STATUS_INTERNAL_SERVER_ERROR, { |
|
|
res.writeHead(constants.HTTP_STATUS_INTERNAL_SERVER_ERROR, { |
|
|
'Content-Language': errorLanguageCode, |
|
|
|
|
|
|
|
|
'Content-Language': errorResponseBodyLanguage.name, |
|
|
}); |
|
|
}); |
|
|
res.statusMessage = errorMessageCollection.statusMessages.unableToSerializeResponse(); |
|
|
|
|
|
|
|
|
res.statusMessage = errorResponseBodyLanguage.statusMessages.unableToSerializeResponse(); |
|
|
res.end(); |
|
|
res.end(); |
|
|
return { |
|
|
return { |
|
|
handled: true, |
|
|
handled: true, |
|
@@ -165,9 +165,9 @@ export const handleGetCollection: Middleware = ({ |
|
|
encoded = encoding.encode(serialized); |
|
|
encoded = encoding.encode(serialized); |
|
|
} catch { |
|
|
} catch { |
|
|
res.writeHead(constants.HTTP_STATUS_INTERNAL_SERVER_ERROR, { |
|
|
res.writeHead(constants.HTTP_STATUS_INTERNAL_SERVER_ERROR, { |
|
|
'Content-Language': errorLanguageCode, |
|
|
|
|
|
|
|
|
'Content-Language': errorResponseBodyLanguage.name, |
|
|
}); |
|
|
}); |
|
|
res.statusMessage = errorMessageCollection.statusMessages.unableToEncodeResponse(); |
|
|
|
|
|
|
|
|
res.statusMessage = errorResponseBodyLanguage.statusMessages.unableToEncodeResponse(); |
|
|
res.end(); |
|
|
res.end(); |
|
|
return { |
|
|
return { |
|
|
handled: true, |
|
|
handled: true, |
|
@@ -176,7 +176,7 @@ export const handleGetCollection: Middleware = ({ |
|
|
|
|
|
|
|
|
const headers: Record<string, string> = { |
|
|
const headers: Record<string, string> = { |
|
|
'Content-Type': responseBodyMediaType, |
|
|
'Content-Type': responseBodyMediaType, |
|
|
'Content-Language': languageCode, |
|
|
|
|
|
|
|
|
'Content-Language': responseBodyLanguage.name, |
|
|
'Content-Encoding': encodingKey, |
|
|
'Content-Encoding': encodingKey, |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
@@ -185,7 +185,7 @@ export const handleGetCollection: Middleware = ({ |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
res.writeHead(constants.HTTP_STATUS_OK, headers); |
|
|
res.writeHead(constants.HTTP_STATUS_OK, headers); |
|
|
res.statusMessage = responseBodyMessageCollection.statusMessages.resourceCollectionFetched(resource); |
|
|
|
|
|
|
|
|
res.statusMessage = responseBodyLanguage.statusMessages.resourceCollectionFetched(resource); |
|
|
res.end(encoded); |
|
|
res.end(encoded); |
|
|
return { |
|
|
return { |
|
|
handled: true |
|
|
handled: true |
|
@@ -196,17 +196,17 @@ export const handleGetItem: Middleware = ({ |
|
|
resourceId, |
|
|
resourceId, |
|
|
resource, |
|
|
resource, |
|
|
responseBodyMediaType: [responseBodyMediaType, responseBodySerializerPair], |
|
|
responseBodyMediaType: [responseBodyMediaType, responseBodySerializerPair], |
|
|
responseBodyLanguage: [languageCode, responseBodyMessageCollection], |
|
|
|
|
|
|
|
|
responseBodyLanguage, |
|
|
responseBodyEncoding: [encodingKey, encoding], |
|
|
responseBodyEncoding: [encodingKey, encoding], |
|
|
errorResponseBodyLanguage: [errorLanguageCode, errorMessageCollection], |
|
|
|
|
|
|
|
|
errorResponseBodyLanguage, |
|
|
}) => async (_req: IncomingMessage, res: ServerResponse) => { |
|
|
}) => async (_req: IncomingMessage, res: ServerResponse) => { |
|
|
try { |
|
|
try { |
|
|
await resource.dataSource.initialize(); |
|
|
await resource.dataSource.initialize(); |
|
|
} catch { |
|
|
} catch { |
|
|
res.writeHead(constants.HTTP_STATUS_INTERNAL_SERVER_ERROR, { |
|
|
res.writeHead(constants.HTTP_STATUS_INTERNAL_SERVER_ERROR, { |
|
|
'Content-Language': errorLanguageCode, |
|
|
|
|
|
|
|
|
'Content-Language': errorResponseBodyLanguage.name, |
|
|
}); |
|
|
}); |
|
|
res.statusMessage = errorMessageCollection.statusMessages.unableToInitializeResourceDataSource(resource); |
|
|
|
|
|
|
|
|
res.statusMessage = errorResponseBodyLanguage.statusMessages.unableToInitializeResourceDataSource(resource); |
|
|
res.end(); |
|
|
res.end(); |
|
|
return { |
|
|
return { |
|
|
handled: true |
|
|
handled: true |
|
@@ -218,9 +218,9 @@ export const handleGetItem: Middleware = ({ |
|
|
data = await resource.dataSource.getById(resourceId); |
|
|
data = await resource.dataSource.getById(resourceId); |
|
|
} catch { |
|
|
} catch { |
|
|
res.writeHead(constants.HTTP_STATUS_INTERNAL_SERVER_ERROR, { |
|
|
res.writeHead(constants.HTTP_STATUS_INTERNAL_SERVER_ERROR, { |
|
|
'Content-Language': errorLanguageCode, |
|
|
|
|
|
|
|
|
'Content-Language': errorResponseBodyLanguage.name, |
|
|
}); |
|
|
}); |
|
|
res.statusMessage = errorMessageCollection.statusMessages.unableToFetchResource(resource); |
|
|
|
|
|
|
|
|
res.statusMessage = errorResponseBodyLanguage.statusMessages.unableToFetchResource(resource); |
|
|
res.end(); |
|
|
res.end(); |
|
|
return { |
|
|
return { |
|
|
handled: true |
|
|
handled: true |
|
@@ -232,9 +232,9 @@ export const handleGetItem: Middleware = ({ |
|
|
serialized = data === null ? null : responseBodySerializerPair.serialize(data); |
|
|
serialized = data === null ? null : responseBodySerializerPair.serialize(data); |
|
|
} catch { |
|
|
} catch { |
|
|
res.writeHead(constants.HTTP_STATUS_INTERNAL_SERVER_ERROR, { |
|
|
res.writeHead(constants.HTTP_STATUS_INTERNAL_SERVER_ERROR, { |
|
|
'Content-Language': errorLanguageCode, |
|
|
|
|
|
|
|
|
'Content-Language': errorResponseBodyLanguage.name, |
|
|
}); |
|
|
}); |
|
|
res.statusMessage = errorMessageCollection.statusMessages.unableToSerializeResponse(); |
|
|
|
|
|
|
|
|
res.statusMessage = errorResponseBodyLanguage.statusMessages.unableToSerializeResponse(); |
|
|
res.end(); |
|
|
res.end(); |
|
|
return { |
|
|
return { |
|
|
handled: true, |
|
|
handled: true, |
|
@@ -246,9 +246,9 @@ export const handleGetItem: Middleware = ({ |
|
|
encoded = serialized === null ? null : encoding.encode(serialized); |
|
|
encoded = serialized === null ? null : encoding.encode(serialized); |
|
|
} catch { |
|
|
} catch { |
|
|
res.writeHead(constants.HTTP_STATUS_INTERNAL_SERVER_ERROR, { |
|
|
res.writeHead(constants.HTTP_STATUS_INTERNAL_SERVER_ERROR, { |
|
|
'Content-Language': errorLanguageCode, |
|
|
|
|
|
|
|
|
'Content-Language': errorResponseBodyLanguage.name, |
|
|
}); |
|
|
}); |
|
|
res.statusMessage = errorMessageCollection.statusMessages.unableToEncodeResponse(); |
|
|
|
|
|
|
|
|
res.statusMessage = errorResponseBodyLanguage.statusMessages.unableToEncodeResponse(); |
|
|
res.end(); |
|
|
res.end(); |
|
|
return { |
|
|
return { |
|
|
handled: true, |
|
|
handled: true, |
|
@@ -258,10 +258,10 @@ export const handleGetItem: Middleware = ({ |
|
|
if (encoded) { |
|
|
if (encoded) { |
|
|
res.writeHead(constants.HTTP_STATUS_OK, { |
|
|
res.writeHead(constants.HTTP_STATUS_OK, { |
|
|
'Content-Type': responseBodyMediaType, |
|
|
'Content-Type': responseBodyMediaType, |
|
|
'Content-Language': languageCode, |
|
|
|
|
|
|
|
|
'Content-Language': responseBodyLanguage.name, |
|
|
'Content-Encoding': encodingKey, |
|
|
'Content-Encoding': encodingKey, |
|
|
}); |
|
|
}); |
|
|
res.statusMessage = responseBodyMessageCollection.statusMessages.resourceFetched(resource) |
|
|
|
|
|
|
|
|
res.statusMessage = responseBodyLanguage.statusMessages.resourceFetched(resource) |
|
|
res.end(encoded); |
|
|
res.end(encoded); |
|
|
return { |
|
|
return { |
|
|
handled: true |
|
|
handled: true |
|
@@ -269,9 +269,9 @@ export const handleGetItem: Middleware = ({ |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
res.writeHead(constants.HTTP_STATUS_NOT_FOUND, { |
|
|
res.writeHead(constants.HTTP_STATUS_NOT_FOUND, { |
|
|
'Content-Language': errorLanguageCode, |
|
|
|
|
|
|
|
|
'Content-Language': errorResponseBodyLanguage.name, |
|
|
}); |
|
|
}); |
|
|
res.statusMessage = errorMessageCollection.statusMessages.resourceNotFound(resource); |
|
|
|
|
|
|
|
|
res.statusMessage = errorResponseBodyLanguage.statusMessages.resourceNotFound(resource); |
|
|
res.end(); |
|
|
res.end(); |
|
|
return { |
|
|
return { |
|
|
handled: true |
|
|
handled: true |
|
@@ -282,17 +282,17 @@ export const handleGetItem: Middleware = ({ |
|
|
export const handleDeleteItem: Middleware = ({ |
|
|
export const handleDeleteItem: Middleware = ({ |
|
|
resource, |
|
|
resource, |
|
|
resourceId, |
|
|
resourceId, |
|
|
responseBodyLanguage: [languageCode, responseBodyMessageCollection], |
|
|
|
|
|
errorResponseBodyLanguage: [errorLanguageCode, errorMessageCollection], |
|
|
|
|
|
|
|
|
responseBodyLanguage, |
|
|
|
|
|
errorResponseBodyLanguage, |
|
|
backendState, |
|
|
backendState, |
|
|
}) => async (_req: IncomingMessage, res: ServerResponse) => { |
|
|
}) => async (_req: IncomingMessage, res: ServerResponse) => { |
|
|
try { |
|
|
try { |
|
|
await resource.dataSource.initialize(); |
|
|
await resource.dataSource.initialize(); |
|
|
} catch { |
|
|
} catch { |
|
|
res.writeHead(constants.HTTP_STATUS_INTERNAL_SERVER_ERROR, { |
|
|
res.writeHead(constants.HTTP_STATUS_INTERNAL_SERVER_ERROR, { |
|
|
'Content-Language': errorLanguageCode, |
|
|
|
|
|
|
|
|
'Content-Language': errorResponseBodyLanguage.name, |
|
|
}); |
|
|
}); |
|
|
res.statusMessage = errorMessageCollection.statusMessages.unableToInitializeResourceDataSource(resource); |
|
|
|
|
|
|
|
|
res.statusMessage = errorResponseBodyLanguage.statusMessages.unableToInitializeResourceDataSource(resource); |
|
|
res.end(); |
|
|
res.end(); |
|
|
return { |
|
|
return { |
|
|
handled: true |
|
|
handled: true |
|
@@ -304,9 +304,9 @@ export const handleDeleteItem: Middleware = ({ |
|
|
existing = await resource.dataSource.getById(resourceId); |
|
|
existing = await resource.dataSource.getById(resourceId); |
|
|
} catch { |
|
|
} catch { |
|
|
res.writeHead(constants.HTTP_STATUS_INTERNAL_SERVER_ERROR, { |
|
|
res.writeHead(constants.HTTP_STATUS_INTERNAL_SERVER_ERROR, { |
|
|
'Content-Language': errorLanguageCode, |
|
|
|
|
|
|
|
|
'Content-Language': errorResponseBodyLanguage.name, |
|
|
}); |
|
|
}); |
|
|
res.statusMessage = errorMessageCollection.statusMessages.unableToFetchResource(resource); |
|
|
|
|
|
|
|
|
res.statusMessage = errorResponseBodyLanguage.statusMessages.unableToFetchResource(resource); |
|
|
res.end(); |
|
|
res.end(); |
|
|
return { |
|
|
return { |
|
|
handled: true |
|
|
handled: true |
|
@@ -315,9 +315,9 @@ export const handleDeleteItem: Middleware = ({ |
|
|
|
|
|
|
|
|
if (!existing && backendState.throws404OnDeletingNotFound) { |
|
|
if (!existing && backendState.throws404OnDeletingNotFound) { |
|
|
res.writeHead(constants.HTTP_STATUS_NOT_FOUND, { |
|
|
res.writeHead(constants.HTTP_STATUS_NOT_FOUND, { |
|
|
'Content-Language': errorLanguageCode, |
|
|
|
|
|
|
|
|
'Content-Language': errorResponseBodyLanguage.name, |
|
|
}); |
|
|
}); |
|
|
res.statusMessage = errorMessageCollection.statusMessages.deleteNonExistingResource(resource); |
|
|
|
|
|
|
|
|
res.statusMessage = errorResponseBodyLanguage.statusMessages.deleteNonExistingResource(resource); |
|
|
res.end(); |
|
|
res.end(); |
|
|
return { |
|
|
return { |
|
|
handled: true |
|
|
handled: true |
|
@@ -330,9 +330,9 @@ export const handleDeleteItem: Middleware = ({ |
|
|
} |
|
|
} |
|
|
} catch { |
|
|
} catch { |
|
|
res.writeHead(constants.HTTP_STATUS_INTERNAL_SERVER_ERROR, { |
|
|
res.writeHead(constants.HTTP_STATUS_INTERNAL_SERVER_ERROR, { |
|
|
'Content-Language': errorLanguageCode, |
|
|
|
|
|
|
|
|
'Content-Language': errorResponseBodyLanguage.name, |
|
|
}); |
|
|
}); |
|
|
res.statusMessage = errorMessageCollection.statusMessages.unableToDeleteResource(resource); |
|
|
|
|
|
|
|
|
res.statusMessage = errorResponseBodyLanguage.statusMessages.unableToDeleteResource(resource); |
|
|
res.end(); |
|
|
res.end(); |
|
|
return { |
|
|
return { |
|
|
handled: true |
|
|
handled: true |
|
@@ -340,9 +340,9 @@ export const handleDeleteItem: Middleware = ({ |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
res.writeHead(constants.HTTP_STATUS_NO_CONTENT, { |
|
|
res.writeHead(constants.HTTP_STATUS_NO_CONTENT, { |
|
|
'Content-Language': languageCode, |
|
|
|
|
|
|
|
|
'Content-Language': responseBodyLanguage.name, |
|
|
}); |
|
|
}); |
|
|
res.statusMessage = responseBodyMessageCollection.statusMessages.resourceDeleted(resource); |
|
|
|
|
|
|
|
|
res.statusMessage = responseBodyLanguage.statusMessages.resourceDeleted(resource); |
|
|
res.end(); |
|
|
res.end(); |
|
|
return { |
|
|
return { |
|
|
handled: true |
|
|
handled: true |
|
@@ -354,18 +354,18 @@ export const handlePatchItem: Middleware = ({ |
|
|
resource, |
|
|
resource, |
|
|
resourceId, |
|
|
resourceId, |
|
|
responseBodyMediaType: [responseBodyMediaType, responseBodySerializerPair], |
|
|
responseBodyMediaType: [responseBodyMediaType, responseBodySerializerPair], |
|
|
responseBodyLanguage: [languageCode, responseBodyMessageCollection], |
|
|
|
|
|
|
|
|
responseBodyLanguage, |
|
|
responseBodyEncoding: [encodingKey, encoding], |
|
|
responseBodyEncoding: [encodingKey, encoding], |
|
|
errorResponseBodyLanguage: [errorLanguageCode, errorMessageCollection], |
|
|
|
|
|
|
|
|
errorResponseBodyLanguage, |
|
|
errorResponseBodyMediaType: [errorMediaType, errorSerializerPair], |
|
|
errorResponseBodyMediaType: [errorMediaType, errorSerializerPair], |
|
|
errorResponseBodyEncoding: [errorEncodingKey, errorEncoding], |
|
|
errorResponseBodyEncoding: [errorEncodingKey, errorEncoding], |
|
|
}) => async (req: IncomingMessage, res: ServerResponse) => { |
|
|
}) => async (req: IncomingMessage, res: ServerResponse) => { |
|
|
const { deserializerPair: requestBodyDeserializerPair, encodingPair: requestBodyEncodingPair } = getDeserializerObjects(appState, req); |
|
|
const { deserializerPair: requestBodyDeserializerPair, encodingPair: requestBodyEncodingPair } = getDeserializerObjects(appState, req); |
|
|
if (typeof requestBodyDeserializerPair === 'undefined' || typeof requestBodyEncodingPair === 'undefined') { |
|
|
if (typeof requestBodyDeserializerPair === 'undefined' || typeof requestBodyEncodingPair === 'undefined') { |
|
|
res.writeHead(constants.HTTP_STATUS_UNSUPPORTED_MEDIA_TYPE, { |
|
|
res.writeHead(constants.HTTP_STATUS_UNSUPPORTED_MEDIA_TYPE, { |
|
|
'Content-Language': errorLanguageCode, |
|
|
|
|
|
|
|
|
'Content-Language': errorResponseBodyLanguage.name, |
|
|
}); |
|
|
}); |
|
|
res.statusMessage = errorMessageCollection.statusMessages.unableToDeserializeRequest(); |
|
|
|
|
|
|
|
|
res.statusMessage = errorResponseBodyLanguage.statusMessages.unableToDeserializeRequest(); |
|
|
res.end(); |
|
|
res.end(); |
|
|
return { |
|
|
return { |
|
|
handled: true |
|
|
handled: true |
|
@@ -376,9 +376,9 @@ export const handlePatchItem: Middleware = ({ |
|
|
await resource.dataSource.initialize(); |
|
|
await resource.dataSource.initialize(); |
|
|
} catch { |
|
|
} catch { |
|
|
res.writeHead(constants.HTTP_STATUS_INTERNAL_SERVER_ERROR, { |
|
|
res.writeHead(constants.HTTP_STATUS_INTERNAL_SERVER_ERROR, { |
|
|
'Content-Language': errorLanguageCode, |
|
|
|
|
|
|
|
|
'Content-Language': errorResponseBodyLanguage.name, |
|
|
}); |
|
|
}); |
|
|
res.statusMessage = errorMessageCollection.statusMessages.unableToInitializeResourceDataSource(resource); |
|
|
|
|
|
|
|
|
res.statusMessage = errorResponseBodyLanguage.statusMessages.unableToInitializeResourceDataSource(resource); |
|
|
res.end(); |
|
|
res.end(); |
|
|
return { |
|
|
return { |
|
|
handled: true |
|
|
handled: true |
|
@@ -390,9 +390,9 @@ export const handlePatchItem: Middleware = ({ |
|
|
existing = await resource.dataSource.getById(resourceId); |
|
|
existing = await resource.dataSource.getById(resourceId); |
|
|
} catch { |
|
|
} catch { |
|
|
res.writeHead(constants.HTTP_STATUS_INTERNAL_SERVER_ERROR, { |
|
|
res.writeHead(constants.HTTP_STATUS_INTERNAL_SERVER_ERROR, { |
|
|
'Content-Language': errorLanguageCode, |
|
|
|
|
|
|
|
|
'Content-Language': errorResponseBodyLanguage.name, |
|
|
}); |
|
|
}); |
|
|
res.statusMessage = errorMessageCollection.statusMessages.unableToFetchResource(resource); |
|
|
|
|
|
|
|
|
res.statusMessage = errorResponseBodyLanguage.statusMessages.unableToFetchResource(resource); |
|
|
res.end(); |
|
|
res.end(); |
|
|
return { |
|
|
return { |
|
|
handled: true |
|
|
handled: true |
|
@@ -401,9 +401,9 @@ export const handlePatchItem: Middleware = ({ |
|
|
|
|
|
|
|
|
if (!existing) { |
|
|
if (!existing) { |
|
|
res.writeHead(constants.HTTP_STATUS_NOT_FOUND, { |
|
|
res.writeHead(constants.HTTP_STATUS_NOT_FOUND, { |
|
|
'Content-Language': errorLanguageCode, |
|
|
|
|
|
|
|
|
'Content-Language': errorResponseBodyLanguage.name, |
|
|
}); |
|
|
}); |
|
|
res.statusMessage = errorMessageCollection.statusMessages.patchNonExistingResource(resource); |
|
|
|
|
|
|
|
|
res.statusMessage = errorResponseBodyLanguage.statusMessages.patchNonExistingResource(resource); |
|
|
res.end(); |
|
|
res.end(); |
|
|
return { |
|
|
return { |
|
|
handled: true |
|
|
handled: true |
|
@@ -428,11 +428,11 @@ export const handlePatchItem: Middleware = ({ |
|
|
} catch (errRaw) { |
|
|
} catch (errRaw) { |
|
|
const err = errRaw as v.ValiError; |
|
|
const err = errRaw as v.ValiError; |
|
|
const headers: Record<string, string> = { |
|
|
const headers: Record<string, string> = { |
|
|
'Content-Language': languageCode, |
|
|
|
|
|
|
|
|
'Content-Language': responseBodyLanguage.name, |
|
|
}; |
|
|
}; |
|
|
if (!Array.isArray(err.issues)) { |
|
|
if (!Array.isArray(err.issues)) { |
|
|
res.writeHead(constants.HTTP_STATUS_BAD_REQUEST, headers) |
|
|
res.writeHead(constants.HTTP_STATUS_BAD_REQUEST, headers) |
|
|
res.statusMessage = errorMessageCollection.statusMessages.invalidResourcePatch(resource); |
|
|
|
|
|
|
|
|
res.statusMessage = errorResponseBodyLanguage.statusMessages.invalidResourcePatch(resource); |
|
|
res.end(); |
|
|
res.end(); |
|
|
return { |
|
|
return { |
|
|
handled: true, |
|
|
handled: true, |
|
@@ -451,7 +451,7 @@ export const handlePatchItem: Middleware = ({ |
|
|
'Content-Type': errorMediaType, |
|
|
'Content-Type': errorMediaType, |
|
|
'Content-Encoding': errorEncodingKey, |
|
|
'Content-Encoding': errorEncodingKey, |
|
|
}) |
|
|
}) |
|
|
res.statusMessage = errorMessageCollection.statusMessages.invalidResourcePatch(resource); |
|
|
|
|
|
|
|
|
res.statusMessage = errorResponseBodyLanguage.statusMessages.invalidResourcePatch(resource); |
|
|
res.end(encoded); |
|
|
res.end(encoded); |
|
|
return { |
|
|
return { |
|
|
handled: true, |
|
|
handled: true, |
|
@@ -464,9 +464,9 @@ export const handlePatchItem: Middleware = ({ |
|
|
newObject = await resource.dataSource.patch(resourceId, params); |
|
|
newObject = await resource.dataSource.patch(resourceId, params); |
|
|
} catch { |
|
|
} catch { |
|
|
res.writeHead(constants.HTTP_STATUS_INTERNAL_SERVER_ERROR, { |
|
|
res.writeHead(constants.HTTP_STATUS_INTERNAL_SERVER_ERROR, { |
|
|
'Content-Language': errorLanguageCode, |
|
|
|
|
|
|
|
|
'Content-Language': errorResponseBodyLanguage.name, |
|
|
}); |
|
|
}); |
|
|
res.statusMessage = errorMessageCollection.statusMessages.unableToPatchResource(resource); |
|
|
|
|
|
|
|
|
res.statusMessage = errorResponseBodyLanguage.statusMessages.unableToPatchResource(resource); |
|
|
res.end(); |
|
|
res.end(); |
|
|
return { |
|
|
return { |
|
|
handled: true, |
|
|
handled: true, |
|
@@ -478,9 +478,9 @@ export const handlePatchItem: Middleware = ({ |
|
|
serialized = responseBodySerializerPair.serialize(newObject); |
|
|
serialized = responseBodySerializerPair.serialize(newObject); |
|
|
} catch { |
|
|
} catch { |
|
|
res.writeHead(constants.HTTP_STATUS_INTERNAL_SERVER_ERROR, { |
|
|
res.writeHead(constants.HTTP_STATUS_INTERNAL_SERVER_ERROR, { |
|
|
'Content-Language': errorLanguageCode, |
|
|
|
|
|
|
|
|
'Content-Language': errorResponseBodyLanguage.name, |
|
|
}); |
|
|
}); |
|
|
res.statusMessage = errorMessageCollection.statusMessages.unableToSerializeResponse(); |
|
|
|
|
|
|
|
|
res.statusMessage = errorResponseBodyLanguage.statusMessages.unableToSerializeResponse(); |
|
|
res.end(); |
|
|
res.end(); |
|
|
return { |
|
|
return { |
|
|
handled: true, |
|
|
handled: true, |
|
@@ -492,9 +492,9 @@ export const handlePatchItem: Middleware = ({ |
|
|
encoded = encoding.encode(serialized); |
|
|
encoded = encoding.encode(serialized); |
|
|
} catch { |
|
|
} catch { |
|
|
res.writeHead(constants.HTTP_STATUS_INTERNAL_SERVER_ERROR, { |
|
|
res.writeHead(constants.HTTP_STATUS_INTERNAL_SERVER_ERROR, { |
|
|
'Content-Language': errorLanguageCode, |
|
|
|
|
|
|
|
|
'Content-Language': errorResponseBodyLanguage.name, |
|
|
}); |
|
|
}); |
|
|
res.statusMessage = errorMessageCollection.statusMessages.unableToEncodeResponse(); |
|
|
|
|
|
|
|
|
res.statusMessage = errorResponseBodyLanguage.statusMessages.unableToEncodeResponse(); |
|
|
res.end(); |
|
|
res.end(); |
|
|
return { |
|
|
return { |
|
|
handled: true, |
|
|
handled: true, |
|
@@ -503,10 +503,10 @@ export const handlePatchItem: Middleware = ({ |
|
|
|
|
|
|
|
|
res.writeHead(constants.HTTP_STATUS_OK, { |
|
|
res.writeHead(constants.HTTP_STATUS_OK, { |
|
|
'Content-Type': responseBodyMediaType, |
|
|
'Content-Type': responseBodyMediaType, |
|
|
'Content-Language': languageCode, |
|
|
|
|
|
|
|
|
'Content-Language': responseBodyLanguage.name, |
|
|
'Content-Encoding': encodingKey, |
|
|
'Content-Encoding': encodingKey, |
|
|
}); |
|
|
}); |
|
|
res.statusMessage = responseBodyMessageCollection.statusMessages.resourcePatched(resource); |
|
|
|
|
|
|
|
|
res.statusMessage = responseBodyLanguage.statusMessages.resourcePatched(resource); |
|
|
res.end(encoded); |
|
|
res.end(encoded); |
|
|
return { |
|
|
return { |
|
|
handled: true |
|
|
handled: true |
|
@@ -520,9 +520,9 @@ export const handleCreateItem: Middleware = ({ |
|
|
serverParams, |
|
|
serverParams, |
|
|
backendState, |
|
|
backendState, |
|
|
responseBodyMediaType: [responseBodyMediaType, responseBodySerializerPair], |
|
|
responseBodyMediaType: [responseBodyMediaType, responseBodySerializerPair], |
|
|
responseBodyLanguage: [languageCode, responseBodyMessageCollection], |
|
|
|
|
|
|
|
|
responseBodyLanguage, |
|
|
responseBodyEncoding: [encodingKey, encoding], |
|
|
responseBodyEncoding: [encodingKey, encoding], |
|
|
errorResponseBodyLanguage: [errorLanguageCode, errorMessageCollection], |
|
|
|
|
|
|
|
|
errorResponseBodyLanguage, |
|
|
errorResponseBodyMediaType: [errorMediaType, errorSerializerPair], |
|
|
errorResponseBodyMediaType: [errorMediaType, errorSerializerPair], |
|
|
errorResponseBodyEncoding: [errorEncodingKey, errorEncoding], |
|
|
errorResponseBodyEncoding: [errorEncodingKey, errorEncoding], |
|
|
resource, |
|
|
resource, |
|
@@ -530,9 +530,9 @@ export const handleCreateItem: Middleware = ({ |
|
|
const { deserializerPair: requestBodyDeserializerPair, encodingPair: requestBodyEncodingPair } = getDeserializerObjects(appState, req); |
|
|
const { deserializerPair: requestBodyDeserializerPair, encodingPair: requestBodyEncodingPair } = getDeserializerObjects(appState, req); |
|
|
if (typeof requestBodyDeserializerPair === 'undefined' || typeof requestBodyEncodingPair === 'undefined') { |
|
|
if (typeof requestBodyDeserializerPair === 'undefined' || typeof requestBodyEncodingPair === 'undefined') { |
|
|
res.writeHead(constants.HTTP_STATUS_UNSUPPORTED_MEDIA_TYPE, { |
|
|
res.writeHead(constants.HTTP_STATUS_UNSUPPORTED_MEDIA_TYPE, { |
|
|
'Content-Language': errorLanguageCode, |
|
|
|
|
|
|
|
|
'Content-Language': errorResponseBodyLanguage.name, |
|
|
}); |
|
|
}); |
|
|
res.statusMessage = errorMessageCollection.statusMessages.unableToDeserializeRequest(); |
|
|
|
|
|
|
|
|
res.statusMessage = errorResponseBodyLanguage.statusMessages.unableToDeserializeRequest(); |
|
|
res.end(); |
|
|
res.end(); |
|
|
return { |
|
|
return { |
|
|
handled: true |
|
|
handled: true |
|
@@ -550,11 +550,11 @@ export const handleCreateItem: Middleware = ({ |
|
|
} catch (errRaw) { |
|
|
} catch (errRaw) { |
|
|
const err = errRaw as v.ValiError; |
|
|
const err = errRaw as v.ValiError; |
|
|
const headers: Record<string, string> = { |
|
|
const headers: Record<string, string> = { |
|
|
'Content-Language': errorLanguageCode, |
|
|
|
|
|
|
|
|
'Content-Language': errorResponseBodyLanguage.name, |
|
|
}; |
|
|
}; |
|
|
if (!Array.isArray(err.issues)) { |
|
|
if (!Array.isArray(err.issues)) { |
|
|
res.writeHead(constants.HTTP_STATUS_BAD_REQUEST, headers) |
|
|
res.writeHead(constants.HTTP_STATUS_BAD_REQUEST, headers) |
|
|
res.statusMessage = errorMessageCollection.statusMessages.invalidResource(resource); |
|
|
|
|
|
|
|
|
res.statusMessage = errorResponseBodyLanguage.statusMessages.invalidResource(resource); |
|
|
res.end(); |
|
|
res.end(); |
|
|
return { |
|
|
return { |
|
|
handled: true, |
|
|
handled: true, |
|
@@ -573,7 +573,7 @@ export const handleCreateItem: Middleware = ({ |
|
|
'Content-Type': errorMediaType, |
|
|
'Content-Type': errorMediaType, |
|
|
'Content-Encoding': errorEncodingKey, |
|
|
'Content-Encoding': errorEncodingKey, |
|
|
}) |
|
|
}) |
|
|
res.statusMessage = errorMessageCollection.statusMessages.invalidResource(resource); |
|
|
|
|
|
|
|
|
res.statusMessage = errorResponseBodyLanguage.statusMessages.invalidResource(resource); |
|
|
res.end(encoded); |
|
|
res.end(encoded); |
|
|
return { |
|
|
return { |
|
|
handled: true, |
|
|
handled: true, |
|
@@ -584,9 +584,9 @@ export const handleCreateItem: Middleware = ({ |
|
|
await resource.dataSource.initialize(); |
|
|
await resource.dataSource.initialize(); |
|
|
} catch { |
|
|
} catch { |
|
|
res.writeHead(constants.HTTP_STATUS_INTERNAL_SERVER_ERROR, { |
|
|
res.writeHead(constants.HTTP_STATUS_INTERNAL_SERVER_ERROR, { |
|
|
'Content-Language': errorLanguageCode, |
|
|
|
|
|
|
|
|
'Content-Language': errorResponseBodyLanguage.name, |
|
|
}); |
|
|
}); |
|
|
res.statusMessage = errorMessageCollection.statusMessages.unableToInitializeResourceDataSource(resource); |
|
|
|
|
|
|
|
|
res.statusMessage = errorResponseBodyLanguage.statusMessages.unableToInitializeResourceDataSource(resource); |
|
|
res.end(); |
|
|
res.end(); |
|
|
return { |
|
|
return { |
|
|
handled: true |
|
|
handled: true |
|
@@ -603,9 +603,9 @@ export const handleCreateItem: Middleware = ({ |
|
|
params[resource.state.idAttr] = newId; |
|
|
params[resource.state.idAttr] = newId; |
|
|
} catch { |
|
|
} catch { |
|
|
res.writeHead(constants.HTTP_STATUS_INTERNAL_SERVER_ERROR, { |
|
|
res.writeHead(constants.HTTP_STATUS_INTERNAL_SERVER_ERROR, { |
|
|
'Content-Language': errorLanguageCode, |
|
|
|
|
|
|
|
|
'Content-Language': errorResponseBodyLanguage.name, |
|
|
}); |
|
|
}); |
|
|
res.statusMessage = errorMessageCollection.statusMessages.unableToGenerateIdFromResourceDataSource(resource); |
|
|
|
|
|
|
|
|
res.statusMessage = errorResponseBodyLanguage.statusMessages.unableToGenerateIdFromResourceDataSource(resource); |
|
|
res.end(); |
|
|
res.end(); |
|
|
return { |
|
|
return { |
|
|
handled: true, |
|
|
handled: true, |
|
@@ -631,9 +631,9 @@ export const handleCreateItem: Middleware = ({ |
|
|
serialized = responseBodySerializerPair.serialize(newObject); |
|
|
serialized = responseBodySerializerPair.serialize(newObject); |
|
|
} catch { |
|
|
} catch { |
|
|
res.writeHead(constants.HTTP_STATUS_INTERNAL_SERVER_ERROR, { |
|
|
res.writeHead(constants.HTTP_STATUS_INTERNAL_SERVER_ERROR, { |
|
|
'Content-Language': errorLanguageCode, |
|
|
|
|
|
|
|
|
'Content-Language': errorResponseBodyLanguage.name, |
|
|
}); |
|
|
}); |
|
|
res.statusMessage = errorMessageCollection.statusMessages.unableToSerializeResponse(); |
|
|
|
|
|
|
|
|
res.statusMessage = errorResponseBodyLanguage.statusMessages.unableToSerializeResponse(); |
|
|
res.end(); |
|
|
res.end(); |
|
|
return { |
|
|
return { |
|
|
handled: true, |
|
|
handled: true, |
|
@@ -645,9 +645,9 @@ export const handleCreateItem: Middleware = ({ |
|
|
encoded = encoding.encode(serialized); |
|
|
encoded = encoding.encode(serialized); |
|
|
} catch { |
|
|
} catch { |
|
|
res.writeHead(constants.HTTP_STATUS_INTERNAL_SERVER_ERROR, { |
|
|
res.writeHead(constants.HTTP_STATUS_INTERNAL_SERVER_ERROR, { |
|
|
'Content-Language': errorLanguageCode, |
|
|
|
|
|
|
|
|
'Content-Language': errorResponseBodyLanguage.name, |
|
|
}); |
|
|
}); |
|
|
res.statusMessage = errorMessageCollection.statusMessages.unableToEncodeResponse(); |
|
|
|
|
|
|
|
|
res.statusMessage = errorResponseBodyLanguage.statusMessages.unableToEncodeResponse(); |
|
|
res.end(); |
|
|
res.end(); |
|
|
return { |
|
|
return { |
|
|
handled: true, |
|
|
handled: true, |
|
@@ -656,7 +656,7 @@ export const handleCreateItem: Middleware = ({ |
|
|
|
|
|
|
|
|
const headers: Record<string, string> = { |
|
|
const headers: Record<string, string> = { |
|
|
'Content-Type': responseBodyMediaType, |
|
|
'Content-Type': responseBodyMediaType, |
|
|
'Content-Language': languageCode, |
|
|
|
|
|
|
|
|
'Content-Language': responseBodyLanguage.name, |
|
|
'Content-Encoding': encodingKey, |
|
|
'Content-Encoding': encodingKey, |
|
|
'Location': `${serverParams.baseUrl}/${resource.state.routeName}/${newId}` |
|
|
'Location': `${serverParams.baseUrl}/${resource.state.routeName}/${newId}` |
|
|
}; |
|
|
}; |
|
@@ -664,7 +664,7 @@ export const handleCreateItem: Middleware = ({ |
|
|
headers['X-Resource-Total-Item-Count'] = totalItemCount.toString(); |
|
|
headers['X-Resource-Total-Item-Count'] = totalItemCount.toString(); |
|
|
} |
|
|
} |
|
|
res.writeHead(constants.HTTP_STATUS_CREATED, headers); |
|
|
res.writeHead(constants.HTTP_STATUS_CREATED, headers); |
|
|
res.statusMessage = responseBodyMessageCollection.statusMessages.resourceCreated(resource); |
|
|
|
|
|
|
|
|
res.statusMessage = responseBodyLanguage.statusMessages.resourceCreated(resource); |
|
|
res.end(encoded); |
|
|
res.end(encoded); |
|
|
return { |
|
|
return { |
|
|
handled: true |
|
|
handled: true |
|
@@ -675,9 +675,9 @@ export const handleEmplaceItem: Middleware = ({ |
|
|
appState, |
|
|
appState, |
|
|
serverParams, |
|
|
serverParams, |
|
|
responseBodyMediaType: [responseBodyMediaType, responseBodySerializerPair], |
|
|
responseBodyMediaType: [responseBodyMediaType, responseBodySerializerPair], |
|
|
responseBodyLanguage: [languageCode, responseBodyMessageCollection], |
|
|
|
|
|
|
|
|
responseBodyLanguage, |
|
|
responseBodyEncoding: [encodingKey, encoding], |
|
|
responseBodyEncoding: [encodingKey, encoding], |
|
|
errorResponseBodyLanguage: [errorLanguageCode, errorMessageCollection], |
|
|
|
|
|
|
|
|
errorResponseBodyLanguage, |
|
|
errorResponseBodyMediaType: [errorMediaType, errorSerializerPair], |
|
|
errorResponseBodyMediaType: [errorMediaType, errorSerializerPair], |
|
|
errorResponseBodyEncoding: [errorEncodingKey, errorEncoding], |
|
|
errorResponseBodyEncoding: [errorEncodingKey, errorEncoding], |
|
|
resource, |
|
|
resource, |
|
@@ -687,9 +687,9 @@ export const handleEmplaceItem: Middleware = ({ |
|
|
const { deserializerPair: requestBodyDeserializerPair, encodingPair: requestBodyEncodingPair } = getDeserializerObjects(appState, req); |
|
|
const { deserializerPair: requestBodyDeserializerPair, encodingPair: requestBodyEncodingPair } = getDeserializerObjects(appState, req); |
|
|
if (typeof requestBodyDeserializerPair === 'undefined' || typeof requestBodyEncodingPair === 'undefined') { |
|
|
if (typeof requestBodyDeserializerPair === 'undefined' || typeof requestBodyEncodingPair === 'undefined') { |
|
|
res.writeHead(constants.HTTP_STATUS_UNSUPPORTED_MEDIA_TYPE, { |
|
|
res.writeHead(constants.HTTP_STATUS_UNSUPPORTED_MEDIA_TYPE, { |
|
|
'Content-Language': errorLanguageCode, |
|
|
|
|
|
|
|
|
'Content-Language': errorResponseBodyLanguage.name, |
|
|
}); |
|
|
}); |
|
|
res.statusMessage = errorMessageCollection.statusMessages.unableToDeserializeRequest(); |
|
|
|
|
|
|
|
|
res.statusMessage = errorResponseBodyLanguage.statusMessages.unableToDeserializeRequest(); |
|
|
res.end(); |
|
|
res.end(); |
|
|
return { |
|
|
return { |
|
|
handled: true |
|
|
handled: true |
|
@@ -719,11 +719,11 @@ export const handleEmplaceItem: Middleware = ({ |
|
|
} catch (errRaw) { |
|
|
} catch (errRaw) { |
|
|
const err = errRaw as v.ValiError; |
|
|
const err = errRaw as v.ValiError; |
|
|
const headers: Record<string, string> = { |
|
|
const headers: Record<string, string> = { |
|
|
'Content-Language': errorLanguageCode, |
|
|
|
|
|
|
|
|
'Content-Language': errorResponseBodyLanguage.name, |
|
|
}; |
|
|
}; |
|
|
if (!Array.isArray(err.issues)) { |
|
|
if (!Array.isArray(err.issues)) { |
|
|
res.writeHead(constants.HTTP_STATUS_BAD_REQUEST, headers) |
|
|
res.writeHead(constants.HTTP_STATUS_BAD_REQUEST, headers) |
|
|
res.statusMessage = errorMessageCollection.statusMessages.invalidResource(resource); |
|
|
|
|
|
|
|
|
res.statusMessage = errorResponseBodyLanguage.statusMessages.invalidResource(resource); |
|
|
res.end(); |
|
|
res.end(); |
|
|
return { |
|
|
return { |
|
|
handled: true, |
|
|
handled: true, |
|
@@ -742,7 +742,7 @@ export const handleEmplaceItem: Middleware = ({ |
|
|
'Content-Type': errorMediaType, |
|
|
'Content-Type': errorMediaType, |
|
|
'Content-Encoding': errorEncodingKey, |
|
|
'Content-Encoding': errorEncodingKey, |
|
|
}) |
|
|
}) |
|
|
res.statusMessage = errorMessageCollection.statusMessages.invalidResource(resource); |
|
|
|
|
|
|
|
|
res.statusMessage = errorResponseBodyLanguage.statusMessages.invalidResource(resource); |
|
|
res.end(encoded); |
|
|
res.end(encoded); |
|
|
return { |
|
|
return { |
|
|
handled: true, |
|
|
handled: true, |
|
@@ -753,9 +753,9 @@ export const handleEmplaceItem: Middleware = ({ |
|
|
await resource.dataSource.initialize(); |
|
|
await resource.dataSource.initialize(); |
|
|
} catch { |
|
|
} catch { |
|
|
res.writeHead(constants.HTTP_STATUS_INTERNAL_SERVER_ERROR, { |
|
|
res.writeHead(constants.HTTP_STATUS_INTERNAL_SERVER_ERROR, { |
|
|
'Content-Language': errorLanguageCode, |
|
|
|
|
|
|
|
|
'Content-Language': errorResponseBodyLanguage.name, |
|
|
}); |
|
|
}); |
|
|
res.statusMessage = errorMessageCollection.statusMessages.unableToInitializeResourceDataSource(resource); |
|
|
|
|
|
|
|
|
res.statusMessage = errorResponseBodyLanguage.statusMessages.unableToInitializeResourceDataSource(resource); |
|
|
res.end(); |
|
|
res.end(); |
|
|
return { |
|
|
return { |
|
|
handled: true |
|
|
handled: true |
|
@@ -770,9 +770,9 @@ export const handleEmplaceItem: Middleware = ({ |
|
|
[newObject, isCreated] = await resource.dataSource.emplace(resourceId, params); |
|
|
[newObject, isCreated] = await resource.dataSource.emplace(resourceId, params); |
|
|
} catch { |
|
|
} catch { |
|
|
res.writeHead(constants.HTTP_STATUS_INTERNAL_SERVER_ERROR, { |
|
|
res.writeHead(constants.HTTP_STATUS_INTERNAL_SERVER_ERROR, { |
|
|
'Content-Language': errorLanguageCode, |
|
|
|
|
|
|
|
|
'Content-Language': errorResponseBodyLanguage.name, |
|
|
}); |
|
|
}); |
|
|
res.statusMessage = errorMessageCollection.statusMessages.unableToEmplaceResource(resource); |
|
|
|
|
|
|
|
|
res.statusMessage = errorResponseBodyLanguage.statusMessages.unableToEmplaceResource(resource); |
|
|
res.end(); |
|
|
res.end(); |
|
|
return { |
|
|
return { |
|
|
handled: true |
|
|
handled: true |
|
@@ -784,9 +784,9 @@ export const handleEmplaceItem: Middleware = ({ |
|
|
serialized = responseBodySerializerPair.serialize(newObject); |
|
|
serialized = responseBodySerializerPair.serialize(newObject); |
|
|
} catch { |
|
|
} catch { |
|
|
res.writeHead(constants.HTTP_STATUS_INTERNAL_SERVER_ERROR, { |
|
|
res.writeHead(constants.HTTP_STATUS_INTERNAL_SERVER_ERROR, { |
|
|
'Content-Language': errorLanguageCode, |
|
|
|
|
|
|
|
|
'Content-Language': errorResponseBodyLanguage.name, |
|
|
}); |
|
|
}); |
|
|
res.statusMessage = errorMessageCollection.statusMessages.unableToSerializeResponse(); |
|
|
|
|
|
|
|
|
res.statusMessage = errorResponseBodyLanguage.statusMessages.unableToSerializeResponse(); |
|
|
res.end(); |
|
|
res.end(); |
|
|
return { |
|
|
return { |
|
|
handled: true, |
|
|
handled: true, |
|
@@ -798,9 +798,9 @@ export const handleEmplaceItem: Middleware = ({ |
|
|
encoded = encoding.encode(serialized); |
|
|
encoded = encoding.encode(serialized); |
|
|
} catch { |
|
|
} catch { |
|
|
res.writeHead(constants.HTTP_STATUS_INTERNAL_SERVER_ERROR, { |
|
|
res.writeHead(constants.HTTP_STATUS_INTERNAL_SERVER_ERROR, { |
|
|
'Content-Language': errorLanguageCode, |
|
|
|
|
|
|
|
|
'Content-Language': errorResponseBodyLanguage.name, |
|
|
}); |
|
|
}); |
|
|
res.statusMessage = errorMessageCollection.statusMessages.unableToEncodeResponse(); |
|
|
|
|
|
|
|
|
res.statusMessage = errorResponseBodyLanguage.statusMessages.unableToEncodeResponse(); |
|
|
res.end(); |
|
|
res.end(); |
|
|
return { |
|
|
return { |
|
|
handled: true, |
|
|
handled: true, |
|
@@ -809,7 +809,7 @@ export const handleEmplaceItem: Middleware = ({ |
|
|
|
|
|
|
|
|
const headers: Record<string, string> = { |
|
|
const headers: Record<string, string> = { |
|
|
'Content-Type': responseBodyMediaType, |
|
|
'Content-Type': responseBodyMediaType, |
|
|
'Content-Language': languageCode, |
|
|
|
|
|
|
|
|
'Content-Language': responseBodyLanguage.name, |
|
|
'Content-Encoding': encodingKey, |
|
|
'Content-Encoding': encodingKey, |
|
|
}; |
|
|
}; |
|
|
let totalItemCount: number | undefined; |
|
|
let totalItemCount: number | undefined; |
|
@@ -825,8 +825,8 @@ export const handleEmplaceItem: Middleware = ({ |
|
|
res.writeHead(isCreated ? constants.HTTP_STATUS_CREATED : constants.HTTP_STATUS_OK, headers); |
|
|
res.writeHead(isCreated ? constants.HTTP_STATUS_CREATED : constants.HTTP_STATUS_OK, headers); |
|
|
res.statusMessage = ( |
|
|
res.statusMessage = ( |
|
|
isCreated |
|
|
isCreated |
|
|
? responseBodyMessageCollection.statusMessages.resourceCreated(resource) |
|
|
|
|
|
: responseBodyMessageCollection.statusMessages.resourceReplaced(resource) |
|
|
|
|
|
|
|
|
? responseBodyLanguage.statusMessages.resourceCreated(resource) |
|
|
|
|
|
: responseBodyLanguage.statusMessages.resourceReplaced(resource) |
|
|
); |
|
|
); |
|
|
res.end(encoded); |
|
|
res.end(encoded); |
|
|
return { |
|
|
return { |
|
|