Skip to content

Commit d3081f6

Browse files
committed
Make it work?
1 parent fc00457 commit d3081f6

File tree

2 files changed

+17
-11
lines changed

2 files changed

+17
-11
lines changed

components/server/src/bitbucket-server/utils.ts

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,22 @@
44
* See License.AGPL.txt in the project root for license information.
55
*/
66

7-
import { HTTPError } from "bitbucket/src/error/types";
7+
import { RequestOptions } from "bitbucket/src/plugins/register-endpoints/types";
88

9-
export class BitbucketHttpError extends Error {
10-
status: number;
11-
constructor(originalErr: HTTPError, message: string) {
12-
if (originalErr.request?.headers.authorization) {
13-
originalErr.request.headers.authorization = "<redacted>";
14-
}
15-
super(message);
16-
}
9+
// this, because for some reason we can't import HTTPError from bitbucket/src/error/types. This is only a subset of the actual class
10+
export abstract class HTTPError extends Error {
11+
public request: RequestOptions | undefined;
1712
}
1813

1914
export function handleBitbucketError(err: Error): Error {
20-
return err instanceof HTTPError ? new BitbucketHttpError(err, "Error parsing BB context") : err;
15+
if (err.name !== "HTTPError") {
16+
return err;
17+
}
18+
19+
const httpError = err as HTTPError;
20+
if (httpError.request?.headers.authorization) {
21+
httpError.request.headers.authorization = "<redacted>";
22+
}
23+
24+
return httpError;
2125
}

components/server/src/bitbucket/bitbucket-repository-provider.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { RepoURL } from "../repohost/repo-url";
1212
import { RepositoryProvider } from "../repohost/repository-provider";
1313
import { BitbucketApiFactory } from "./bitbucket-api-factory";
1414
import asyncBatch from "async-batch";
15+
import { handleBitbucketError } from "../bitbucket-server/utils";
1516

1617
@injectable()
1718
export class BitbucketRepositoryProvider implements RepositoryProvider {
@@ -124,7 +125,8 @@ export class BitbucketRepositoryProvider implements RepositoryProvider {
124125
async hasReadAccess(user: User, owner: string, repo: string): Promise<boolean> {
125126
const api = await this.apiFactory.create(user);
126127
const result = await api.repositories.get({ workspace: owner, repo_slug: repo }).catch((e) => {
127-
console.warn({ userId: user.id }, "hasReadAccess error", { owner, repo, status: e.status });
128+
const error = e instanceof Error ? handleBitbucketError(e) : e;
129+
console.warn({ userId: user.id }, "hasReadAccess error", error, { owner, repo });
128130
return null;
129131
});
130132

0 commit comments

Comments
 (0)