fix(settings): complete DingTalk scan login flow
This commit is contained in:
@@ -46,6 +46,17 @@ export interface RegisteredDingtalkSpace {
|
||||
name: string
|
||||
}
|
||||
|
||||
export class DingtalkRequestError extends Error {
|
||||
constructor(
|
||||
message: string,
|
||||
public readonly code: string,
|
||||
public readonly status: number,
|
||||
) {
|
||||
super(message)
|
||||
this.name = 'DingtalkRequestError'
|
||||
}
|
||||
}
|
||||
|
||||
// Register a DingTalk knowledge-base space (URL or bare space id) as a new
|
||||
// source connection. Errors carry the sidecar's machine codes so the UI can
|
||||
// explain them: login_required, space_not_found, name_conflict.
|
||||
@@ -67,7 +78,11 @@ export async function registerDingtalkSpace(url: string): Promise<RegisteredDing
|
||||
name_conflict: '该空间与已登记的来源同名',
|
||||
invalid_space_url: '链接不是有效的钉钉知识库空间地址(应形如 alidocs.dingtalk.com/i/spaces/…)',
|
||||
}
|
||||
throw new Error(friendly[code] || `登记钉钉知识库失败(HTTP ${response.status}${code ? ':' + code : ''})`)
|
||||
throw new DingtalkRequestError(
|
||||
friendly[code] || `登记钉钉知识库失败(HTTP ${response.status}${code ? ':' + code : ''})`,
|
||||
code,
|
||||
response.status,
|
||||
)
|
||||
}
|
||||
const value = await response.json() as unknown
|
||||
if (!isRecord(value) || !isRecord(value.data)) throw new Error('invalid dingtalk space response')
|
||||
|
||||
Reference in New Issue
Block a user