@epistemology-factory/crocks-web
Advanced tools
Comparing version 0.2.7 to 0.2.8
{ | ||
"name": "@epistemology-factory/crocks-web", | ||
"version": "0.2.7", | ||
"version": "0.2.8", | ||
"description": "Functions to help write web applications with crocks", | ||
@@ -5,0 +5,0 @@ "scripts": { |
@@ -21,6 +21,12 @@ "use strict"; | ||
const anInvalidEnvVar = (name) => anEnvVarError(ERROR_TYPES.INVALID_ENV_VAR, name) | ||
const anInvalidEnvVarError = (name) => anEnvVarError(ERROR_TYPES.INVALID_ENV_VAR, name) | ||
const aMissingEnvVar = (name) => anEnvVarError(ERROR_TYPES.MISSING_ENV_VAR, name) | ||
const aMissingEnvVarError = (name) => anEnvVarError(ERROR_TYPES.MISSING_ENV_VAR, name) | ||
const anInvalidContentTypeError = (contentType) => | ||
allOf( | ||
anError(contentType), | ||
hasProperty("contentType", equalTo(contentType)) | ||
) | ||
const aValidationError = (failures) => | ||
@@ -34,5 +40,6 @@ allOf( | ||
anError, | ||
anInvalidEnvVar, | ||
aMissingEnvVar, | ||
anInvalidContentTypeError, | ||
anInvalidEnvVarError, | ||
aMissingEnvVarError, | ||
aValidationError | ||
} |
@@ -28,6 +28,15 @@ "use strict"; | ||
// anUnsupportedMediaType :: (Object, String) -> Matcher | ||
const anUnsupportedMediaType = (headers, contentType) => anErrorResponse( | ||
415, | ||
headers, | ||
`'${contentType}' is unsupported`, | ||
{} | ||
) | ||
module.exports = { | ||
aBadRequest, | ||
anInternalServerError, | ||
anUnsupportedMediaType, | ||
aResponse | ||
} |
@@ -22,3 +22,3 @@ "use strict"; | ||
const { badRequest, internalServerError } = require("./responses"); | ||
const { badRequest, internalServerError, unsupportedMediaType } = require("./responses"); | ||
@@ -62,2 +62,7 @@ // genericError :: (Object -> String) -> Object -> Object | ||
// mapInvalidContentType :: Object -> Object -> Object | ||
const mapInvalidContentType = curry((headers) => | ||
({ contentType }) => unsupportedMediaType(headers, contentType) | ||
) | ||
// mapValidationError :: Object -> Object -> Object | ||
@@ -77,3 +82,4 @@ const mapValidationError = curry((headers) => | ||
mapError, | ||
mapInvalidContentType, | ||
mapValidationError | ||
} |
"use strict"; | ||
const flip = require("crocks/combinators/flip"); | ||
const objOf = require("crocks/helpers/objOf"); | ||
@@ -8,2 +9,3 @@ const pipe = require("crocks/helpers/pipe"); | ||
const ERROR_TYPES = { | ||
INVALID_CONTENT_TYPE: "invalid-content-type", | ||
INVALID_ENV_VAR: "invalid-env-var", | ||
@@ -14,2 +16,8 @@ MISSING_ENV_VAR: "missing-env-var", | ||
// invalidContentType :: String -> Object | ||
const invalidContentType = | ||
flip(setProp("contentType"), { | ||
type: ERROR_TYPES.INVALID_CONTENT_TYPE | ||
}) | ||
// validationError :: [ValidationFailures] -> Object | ||
@@ -36,2 +44,3 @@ const validationError = (failures) => ({ | ||
ERROR_TYPES, | ||
invalidContentType, | ||
invalidEnvVar, | ||
@@ -38,0 +47,0 @@ missingEnvVar, |
@@ -64,4 +64,6 @@ "use strict"; | ||
// invalidMediaType :: Object -> Object | ||
const invalidMediaType = (headers) => errorResponse(415, headers, "Invalid media type", {}) | ||
// unsupportedMediaType :: Object -> String -> Object | ||
const unsupportedMediaType = curry((headers, contentType) => | ||
errorResponse(415, headers, `'${contentType}' is unsupported`, {}) | ||
) | ||
@@ -71,5 +73,5 @@ module.exports = { | ||
internalServerError, | ||
invalidMediaType, | ||
respondWith, | ||
response | ||
response, | ||
unsupportedMediaType | ||
} |
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
28293
776