https://github.com/jfrazx/status-codes
Collection of status code enums
https://github.com/jfrazx/status-codes
Last synced: about 2 months ago
JSON representation
Collection of status code enums
- Host: GitHub
- URL: https://github.com/jfrazx/status-codes
- Owner: jfrazx
- License: mit
- Created: 2018-08-05T07:10:52.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2025-04-05T06:19:22.000Z (about 1 year ago)
- Last Synced: 2025-04-13T09:05:20.141Z (about 1 year ago)
- Language: TypeScript
- Homepage:
- Size: 1.68 MB
- Stars: 6
- Watchers: 1
- Forks: 0
- Open Issues: 9
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Status Codes
[](https://www.npmjs.com/package/@status/codes)
[](LICENSE)
A collection of status code enums.
## Available Enums
- Apache
- Auth0
- Braintree
- Cloudflare
- FirebaseAuth
- FirebaseAdminAuth
- FirebaseAnalytics
- FirebaseMessaging
- FTP
- Http
- IIS
- IRC
- Mocha
- MongoDB
- Mongoose \*wip
- Nginx
- Node
- Postgres
- Prisma
- Twitter
## Install
npm:
`npm install @status/codes`
yarn:
`yarn add @status/codes`
## Example Usage
```typescript
import { Http } from '@status/codes';
export class NotFoundError extends Error {
readonly code = Http.NotFound;
}
```
Use with express:
```javascript
const { Http } = require('@status/codes');
create(request, response) {
return Model.create(request.body)
.then(instance => response.status(Http.Created).json(instance))
.catch(error => response.status(Http.Conflict).json(error))
}
```
Or Nestjs:
```typescript
import { Injectable, NotFoundException } from '@nestjs/common';
import { DatabaseService, Prisma } from '@my-app/database';
import { PrismaError } from '@status/codes';
@Injectable()
export class UserService {
constructor(private readonly db: DatabaseService) {}
async getUserById(id: string) {
try {
return await this.db.user.findUniqueOrThrow({
where: { id },
});
} catch (error) {
if (error instanceof Prisma.PrismaClientKnownRequestError) {
if (error.code === PrismaError.DependentRecordNotFound) {
throw new NotFoundException(`User with id ${id} not found`);
}
}
throw error;
}
}
}
```