mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-19 19:16:29 +08:00
test: throw no permission when download failed (#1742)
This commit is contained in:
@@ -5,9 +5,12 @@ import { z } from 'zod';
|
||||
import { getLoginStorage } from '../login';
|
||||
|
||||
export class RequestError extends Error {
|
||||
public readonly code: MessageCode;
|
||||
|
||||
constructor(code: MessageCode, cause: unknown | null = null) {
|
||||
super(Messages[code].message);
|
||||
sendMessage(code);
|
||||
this.code = code;
|
||||
this.name = 'RequestError';
|
||||
this.cause = cause;
|
||||
}
|
||||
@@ -360,8 +363,16 @@ export function createWorkspaceApis(prefixUrl = '/') {
|
||||
Authorization: auth.token,
|
||||
},
|
||||
})
|
||||
.then(r =>
|
||||
r.status === 403
|
||||
? Promise.reject(new RequestError(MessageCode.noPermission))
|
||||
: r
|
||||
)
|
||||
.then(r => r.arrayBuffer())
|
||||
.catch(e => {
|
||||
if (e instanceof RequestError) {
|
||||
throw e;
|
||||
}
|
||||
throw new RequestError(MessageCode.downloadWorkspaceFailed, e);
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user