mirror of
https://github.com/roleypoly/roleypoly-v1.git
synced 2025-04-28 13:39:11 +00:00
21 lines
446 B
JavaScript
21 lines
446 B
JavaScript
// @flow
|
|
import type { RPCResponse } from './index'
|
|
|
|
class RPCError extends Error {
|
|
code: ?number
|
|
extra: any[]
|
|
remoteStack: ?string
|
|
constructor (msg: string, code?: number, ...extra: any[]) {
|
|
super(msg)
|
|
this.code = code
|
|
this.extra = extra
|
|
}
|
|
|
|
static fromResponse (body: RPCResponse, status: number) {
|
|
const e = new RPCError(body.msg, status)
|
|
e.remoteStack = body.trace
|
|
return e
|
|
}
|
|
}
|
|
|
|
module.exports = RPCError
|