Skip to content

Commit

Permalink
feat(core): support SenderError.selfId
Browse files Browse the repository at this point in the history
  • Loading branch information
shigma committed Mar 11, 2020
1 parent 49aee5f commit 77efd54
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
2 changes: 1 addition & 1 deletion packages/koishi-core/src/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ export class Command {
option (rawName: string, description: string, config?: OptionConfig): this
option (rawName: string, ...args: [OptionConfig?] | [string, OptionConfig?]) {
const description = typeof args[0] === 'string' ? args.shift() as string : undefined
const config = args[0] as CommandConfig || {}
const config = args[0] as OptionConfig || {}
const option = parseOption(rawName, description, config, this._optsDef)
this._options.push(option)
for (const name of option.names) {
Expand Down
7 changes: 4 additions & 3 deletions packages/koishi-core/src/sender.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@ import {
} from './meta'

export class SenderError extends Error {
constructor (args: Record<string, any>, url: string, retcode: number) {
constructor (args: Record<string, any>, url: string, retcode: number, selfId: number) {
super(`Error when trying to send to ${url}, args: ${JSON.stringify(args)}, retcode: ${retcode}`)
Object.defineProperties(this, {
name: { value: 'SenderError' },
selfId: { value: selfId },
code: { value: retcode },
args: { value: args },
url: { value: url },
Expand Down Expand Up @@ -77,9 +78,9 @@ export class Sender {
if (retcode === 0 && !silent) {
return camelCase(data)
} else if (retcode < 0 && !silent) {
throw new SenderError(params, action, retcode)
throw new SenderError(params, action, retcode, this.app.selfId)
} else if (retcode > 1) {
throw new SenderError(params, action, retcode)
throw new SenderError(params, action, retcode, this.app.selfId)
}
}

Expand Down

0 comments on commit 77efd54

Please sign in to comment.