test: throw no permission when download failed (#1742)

This commit is contained in:
Himself65
2023-03-29 13:42:55 -05:00
committed by GitHub
parent 8a03f9ff1f
commit 9cd59d9146
2 changed files with 24 additions and 12 deletions
@@ -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);
});
}