[add] first
This commit is contained in:
10
test/api/ApiObjId.ts
Normal file
10
test/api/ApiObjId.ts
Normal file
@@ -0,0 +1,10 @@
|
||||
import { ApiCall } from "../../src/server/base/ApiCall";
|
||||
import { ReqObjId, ResObjId } from "../proto/PtlObjId";
|
||||
|
||||
export async function ApiObjId(call: ApiCall<ReqObjId, ResObjId>) {
|
||||
call.succ({
|
||||
id2: call.req.id1,
|
||||
buf: call.req.buf,
|
||||
date: call.req.date
|
||||
})
|
||||
}
|
||||
27
test/api/ApiTest.ts
Normal file
27
test/api/ApiTest.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
import { TsrpcError } from "tsrpc-proto";
|
||||
import { ApiCall } from "../../src/server/base/ApiCall";
|
||||
import { ReqTest, ResTest } from "../proto/PtlTest";
|
||||
|
||||
export async function ApiTest(call: ApiCall<ReqTest, ResTest>) {
|
||||
if (call.req.name === 'InnerError') {
|
||||
await new Promise(rs => { setTimeout(rs, 50) })
|
||||
throw new Error('Test InnerError')
|
||||
}
|
||||
else if (call.req.name === 'TsrpcError') {
|
||||
await new Promise(rs => { setTimeout(rs, 50) })
|
||||
throw new TsrpcError('Test TsrpcError', {
|
||||
code: 'CODE_TEST',
|
||||
info: 'ErrInfo Test'
|
||||
});
|
||||
}
|
||||
else if (call.req.name === 'error') {
|
||||
await new Promise(rs => { setTimeout(rs, 50) })
|
||||
call.error('Got an error')
|
||||
}
|
||||
else {
|
||||
await new Promise(rs => { setTimeout(rs, 50) })
|
||||
call.succ({
|
||||
reply: 'Test reply: ' + call.req.name
|
||||
})
|
||||
}
|
||||
}
|
||||
21
test/api/a/b/c/ApiTest.ts
Normal file
21
test/api/a/b/c/ApiTest.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
import { TsrpcError } from "tsrpc-proto";
|
||||
|
||||
export async function ApiTest(call: any) {
|
||||
if (call.req.name === 'InnerError') {
|
||||
throw new Error('a/b/c/Test InnerError')
|
||||
}
|
||||
else if (call.req.name === 'TsrpcError') {
|
||||
throw new TsrpcError('a/b/c/Test TsrpcError', {
|
||||
code: 'CODE_TEST',
|
||||
info: 'ErrInfo a/b/c/Test'
|
||||
});
|
||||
}
|
||||
else if (call.req.name === 'error') {
|
||||
call.error('Got an error')
|
||||
}
|
||||
else {
|
||||
call.succ({
|
||||
reply: 'a/b/c/Test reply: ' + call.req.name
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user