diff --git a/package-lock.json b/package-lock.json index 33fb265..ed30b6d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,6 +10,7 @@ "@js-temporal/polyfill": "^0.4.4", "doi-regex": "^0.1.13", "effect": "^2.0.0-next.58", + "http-status-codes": "^2.3.0", "ioredis": "^5.3.2" }, "devDependencies": { @@ -97,9 +98,9 @@ } }, "node_modules/@babel/helper-function-name/node_modules/@babel/types": { - "version": "7.23.5", - "resolved": "https://registry.npmjs.org/@babel/types/-/types-7.23.5.tgz", - "integrity": "sha512-ON5kSOJwVO6xXVRTvOI0eOnWe7VdUcIpsovGo9U/Br4Ie4UVFQTboO2cYnDhAGU6Fp+UxSiT+pMft0SMHfuq6w==", + "version": "7.23.6", + "resolved": "https://registry.npmjs.org/@babel/types/-/types-7.23.6.tgz", + "integrity": "sha512-+uarb83brBzPKN38NX1MkB6vb6+mwvR6amUulqAE7ccQw1pEl+bCia9TbdG1lsnFP7lZySvUn37CHyXQdfTwzg==", "dev": true, "dependencies": { "@babel/helper-string-parser": "^7.23.4", @@ -123,9 +124,9 @@ } }, "node_modules/@babel/helper-hoist-variables/node_modules/@babel/types": { - "version": "7.23.5", - "resolved": "https://registry.npmjs.org/@babel/types/-/types-7.23.5.tgz", - "integrity": "sha512-ON5kSOJwVO6xXVRTvOI0eOnWe7VdUcIpsovGo9U/Br4Ie4UVFQTboO2cYnDhAGU6Fp+UxSiT+pMft0SMHfuq6w==", + "version": "7.23.6", + "resolved": "https://registry.npmjs.org/@babel/types/-/types-7.23.6.tgz", + "integrity": "sha512-+uarb83brBzPKN38NX1MkB6vb6+mwvR6amUulqAE7ccQw1pEl+bCia9TbdG1lsnFP7lZySvUn37CHyXQdfTwzg==", "dev": true, "dependencies": { "@babel/helper-string-parser": "^7.23.4", @@ -149,9 +150,9 @@ } }, "node_modules/@babel/helper-split-export-declaration/node_modules/@babel/types": { - "version": "7.23.5", - "resolved": "https://registry.npmjs.org/@babel/types/-/types-7.23.5.tgz", - "integrity": "sha512-ON5kSOJwVO6xXVRTvOI0eOnWe7VdUcIpsovGo9U/Br4Ie4UVFQTboO2cYnDhAGU6Fp+UxSiT+pMft0SMHfuq6w==", + "version": "7.23.6", + "resolved": "https://registry.npmjs.org/@babel/types/-/types-7.23.6.tgz", + "integrity": "sha512-+uarb83brBzPKN38NX1MkB6vb6+mwvR6amUulqAE7ccQw1pEl+bCia9TbdG1lsnFP7lZySvUn37CHyXQdfTwzg==", "dev": true, "dependencies": { "@babel/helper-string-parser": "^7.23.4", @@ -221,9 +222,9 @@ } }, "node_modules/@babel/template/node_modules/@babel/types": { - "version": "7.23.5", - "resolved": "https://registry.npmjs.org/@babel/types/-/types-7.23.5.tgz", - "integrity": "sha512-ON5kSOJwVO6xXVRTvOI0eOnWe7VdUcIpsovGo9U/Br4Ie4UVFQTboO2cYnDhAGU6Fp+UxSiT+pMft0SMHfuq6w==", + "version": "7.23.6", + "resolved": "https://registry.npmjs.org/@babel/types/-/types-7.23.6.tgz", + "integrity": "sha512-+uarb83brBzPKN38NX1MkB6vb6+mwvR6amUulqAE7ccQw1pEl+bCia9TbdG1lsnFP7lZySvUn37CHyXQdfTwzg==", "dev": true, "dependencies": { "@babel/helper-string-parser": "^7.23.4", @@ -256,12 +257,12 @@ } }, "node_modules/@babel/traverse/node_modules/@babel/generator": { - "version": "7.23.5", - "resolved": "https://registry.npmjs.org/@babel/generator/-/generator-7.23.5.tgz", - "integrity": "sha512-BPssCHrBD+0YrxviOa3QzpqwhNIXKEtOa2jQrm4FlmkC2apYgRnQcmPWiGZDlGxiNtltnUFolMe8497Esry+jA==", + "version": "7.23.6", + "resolved": "https://registry.npmjs.org/@babel/generator/-/generator-7.23.6.tgz", + "integrity": "sha512-qrSfCYxYQB5owCmGLbl8XRpX1ytXlpueOb0N0UmQwA073KZxejgQTzAmJezxvpwQD9uGtK2shHdi55QT+MbjIw==", "dev": true, "dependencies": { - "@babel/types": "^7.23.5", + "@babel/types": "^7.23.6", "@jridgewell/gen-mapping": "^0.3.2", "@jridgewell/trace-mapping": "^0.3.17", "jsesc": "^2.5.1" @@ -271,9 +272,9 @@ } }, "node_modules/@babel/traverse/node_modules/@babel/types": { - "version": "7.23.5", - "resolved": "https://registry.npmjs.org/@babel/types/-/types-7.23.5.tgz", - "integrity": "sha512-ON5kSOJwVO6xXVRTvOI0eOnWe7VdUcIpsovGo9U/Br4Ie4UVFQTboO2cYnDhAGU6Fp+UxSiT+pMft0SMHfuq6w==", + "version": "7.23.6", + "resolved": "https://registry.npmjs.org/@babel/types/-/types-7.23.6.tgz", + "integrity": "sha512-+uarb83brBzPKN38NX1MkB6vb6+mwvR6amUulqAE7ccQw1pEl+bCia9TbdG1lsnFP7lZySvUn37CHyXQdfTwzg==", "dev": true, "dependencies": { "@babel/helper-string-parser": "^7.23.4", @@ -733,9 +734,9 @@ } }, "node_modules/@eslint/eslintrc/node_modules/globals": { - "version": "13.23.0", - "resolved": "https://registry.npmjs.org/globals/-/globals-13.23.0.tgz", - "integrity": "sha512-XAmF0RjlrjY23MA51q3HltdlGxUpXPvg0GioKiD9X6HD28iMjo2dKC8Vqwm7lne4GNr78+RHTfliktR6ZH09wA==", + "version": "13.24.0", + "resolved": "https://registry.npmjs.org/globals/-/globals-13.24.0.tgz", + "integrity": "sha512-AhO5QUcj8llrbG09iWhPU2B204J1xnPeL8kQmVorSsy+Sjj1sk8gIyh6cUocGmH4L0UuhAJy+hJMRA4mgA4mFQ==", "dev": true, "dependencies": { "type-fest": "^0.20.2" @@ -2379,9 +2380,9 @@ } }, "node_modules/eslint/node_modules/globals": { - "version": "13.23.0", - "resolved": "https://registry.npmjs.org/globals/-/globals-13.23.0.tgz", - "integrity": "sha512-XAmF0RjlrjY23MA51q3HltdlGxUpXPvg0GioKiD9X6HD28iMjo2dKC8Vqwm7lne4GNr78+RHTfliktR6ZH09wA==", + "version": "13.24.0", + "resolved": "https://registry.npmjs.org/globals/-/globals-13.24.0.tgz", + "integrity": "sha512-AhO5QUcj8llrbG09iWhPU2B204J1xnPeL8kQmVorSsy+Sjj1sk8gIyh6cUocGmH4L0UuhAJy+hJMRA4mgA4mFQ==", "dev": true, "dependencies": { "type-fest": "^0.20.2" @@ -2968,6 +2969,11 @@ "node": ">= 0.4" } }, + "node_modules/http-status-codes": { + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/http-status-codes/-/http-status-codes-2.3.0.tgz", + "integrity": "sha512-RJ8XvFvpPM/Dmc5SV+dC4y5PCeOhT3x1Hq0NU3rjGeg5a/CqlhZ7uudknPwZFz4aeAXDcbAyaeP7GAo9lvngtA==" + }, "node_modules/human-signals": { "version": "5.0.0", "resolved": "https://registry.npmjs.org/human-signals/-/human-signals-5.0.0.tgz", diff --git a/package.json b/package.json index 94cbafa..3ca1f97 100644 --- a/package.json +++ b/package.json @@ -11,6 +11,7 @@ "@js-temporal/polyfill": "^0.4.4", "doi-regex": "^0.1.13", "effect": "^2.0.0-next.58", + "http-status-codes": "^2.3.0", "ioredis": "^5.3.2" }, "devDependencies": { diff --git a/src/Router.ts b/src/Router.ts index 4a73bc3..5ba5947 100644 --- a/src/Router.ts +++ b/src/Router.ts @@ -1,6 +1,7 @@ import { HttpServer } from '@effect/platform-node' import { Schema, TreeFormatter } from '@effect/schema' import { Context, Data, Effect } from 'effect' +import { StatusCodes } from 'http-status-codes' import * as CoarNotify from './CoarNotify.js' import * as Doi from './Doi.js' import * as Redis from './Redis.js' @@ -35,13 +36,13 @@ export const Router = HttpServer.router.empty.pipe( Effect.gen(function* (_) { yield* _(Effect.logError('Unable to ping Redis').pipe(Effect.annotateLogs({ message: error.message }))) - return yield* _(HttpServer.response.json({ status: 'error' }, { status: 503 })) + return yield* _(HttpServer.response.json({ status: 'error' }, { status: StatusCodes.SERVICE_UNAVAILABLE })) }), RedisTimeout: error => Effect.gen(function* (_) { yield* _(Effect.logError('Unable to ping Redis').pipe(Effect.annotateLogs({ message: error.message }))) - return yield* _(HttpServer.response.json({ status: 'error' }, { status: 503 })) + return yield* _(HttpServer.response.json({ status: 'error' }, { status: StatusCodes.SERVICE_UNAVAILABLE })) }), }), ), @@ -91,7 +92,7 @@ export const Router = HttpServer.router.empty.pipe( }), ) - return yield* _(HttpServer.response.empty({ status: 201 })) + return yield* _(HttpServer.response.empty({ status: StatusCodes.CREATED })) }).pipe( Effect.catchTags({ ParseError: error => @@ -102,7 +103,7 @@ export const Router = HttpServer.router.empty.pipe( ), ) - return HttpServer.response.empty({ status: 400 }) + return HttpServer.response.empty({ status: StatusCodes.BAD_REQUEST }) }), RedisError: error => Effect.gen(function* (_) { @@ -112,9 +113,9 @@ export const Router = HttpServer.router.empty.pipe( ), ) - return HttpServer.response.empty({ status: 503 }) + return HttpServer.response.empty({ status: StatusCodes.SERVICE_UNAVAILABLE }) }), - RequestError: () => HttpServer.response.empty({ status: 400 }), + RequestError: () => HttpServer.response.empty({ status: StatusCodes.BAD_REQUEST }), SlackErrorResponse: error => Effect.gen(function* (_) { yield* _( @@ -123,11 +124,11 @@ export const Router = HttpServer.router.empty.pipe( ), ) - return HttpServer.response.empty({ status: 503 }) + return HttpServer.response.empty({ status: StatusCodes.SERVICE_UNAVAILABLE }) }), }), ), ), - Effect.catchTag('RouteNotFound', () => HttpServer.response.empty({ status: 404 })), + Effect.catchTag('RouteNotFound', () => HttpServer.response.empty({ status: StatusCodes.NOT_FOUND })), HttpServer.server.serve(HttpServer.middleware.logger), )