Skip to content

Commit 4f386a4

Browse files
author
梅世祺
committed
feat: add errors
1 parent 18183cd commit 4f386a4

11 files changed

Lines changed: 109 additions & 1 deletion

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
node_modules
2+
.DS_Store
3+
dist

README.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,8 @@
1-
# askcodebase-common
1+
# askcodebase-common
2+
3+
## Deveop
4+
5+
```
6+
pnpm i
7+
pnpm watch
8+
```

package.json

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"name": "@askcodebase/common",
3+
"version": "1.0.0",
4+
"description": "Common types, definitions for AskCodebase client and server.",
5+
"main": "dist/index.js",
6+
"types": "dist/index.d.ts",
7+
"scripts": {
8+
"watch": "tsc --watch",
9+
"build": "tsc"
10+
},
11+
"repository": {
12+
"type": "git",
13+
"url": "git+https://github.com/jipitiai/askcodebase-common.git"
14+
},
15+
"keywords": [],
16+
"author": "",
17+
"license": "ISC",
18+
"bugs": {
19+
"url": "https://github.com/jipitiai/askcodebase-common/issues"
20+
},
21+
"homepage": "https://github.com/jipitiai/askcodebase-common#readme",
22+
"devDependencies": {
23+
"typescript": "^5.1.6"
24+
}
25+
}

pnpm-lock.yaml

Lines changed: 18 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/errors/AskCodebaseError.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { AskCodebaseErrorCode } from "./AskCodebaseErrorCode";
2+
3+
export class AskCodebaseError extends Error {
4+
public code: AskCodebaseErrorCode = AskCodebaseErrorCode.E1000;
5+
6+
constructor(code: AskCodebaseErrorCode, message: string) {
7+
super(message);
8+
this.code = code;
9+
}
10+
}

src/errors/AskCodebaseErrorCode.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
export enum AskCodebaseErrorCode {
2+
/** Unkonwn error */
3+
E1000 = 'E1000',
4+
/** Access token expired */
5+
E1001 = 'E1001',
6+
/** API usage limit exceeded */
7+
E1002 = 'E1002',
8+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { AskCodebaseError } from "./AskCodebaseError";
2+
import { AskCodebaseErrorCode } from "./AskCodebaseErrorCode";
3+
4+
export class ErrorApiUsageExceeded extends AskCodebaseError {
5+
constructor(message: string) {
6+
super(AskCodebaseErrorCode.E1002, message);
7+
}
8+
}

src/errors/ErrorTokenExpired.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { AskCodebaseError } from "./AskCodebaseError";
2+
import { AskCodebaseErrorCode } from "./AskCodebaseErrorCode";
3+
4+
export class ErrorTokenExpired extends AskCodebaseError {
5+
constructor(message: string) {
6+
super(AskCodebaseErrorCode.E1001, message);
7+
}
8+
}

src/errors/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export * from './AskCodebaseErrorCode'
2+
export * from './AskCodebaseError'
3+
export * from './ErrorTokenExpired'
4+
export * from './ErrorApiUsageExceeded'

src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './errors'

0 commit comments

Comments
 (0)