可能是由于缺少必要的授权令牌或者权限不足导致的。可以尝试在调用API前加入必要的授权信息或者检查是否有足够的权限。示例代码如下:
import { AbpMultiTenancyService } from '@abp/multi-tenancy/abp-multi-tenancy.service';
import { impersonating } from '@abp/session/impersonating';
import { SubscriptionStartType } from '../../../../../src/shared/service-proxies/service-proxies';
export class MyServiceProxy {
constructor(
private http: HttpClient,
private apiBaseUrlService: ApiBaseUrlService,
private abpMultiTenancyService: AbpMultiTenancyService,
private authService: AuthService
) {}
get(url: string, params?: any) {
return this.http.get(this.formatUrl(url), {
headers: this.headers,
params,
withCredentials: true
})
.pipe(
catchError(error => this.handleError(error)),
tap(() => this.handleExceptions())
);
}
private get headers() {
let headers = {
'Content-Type': 'application/json',
'Pragma': 'no-cache',
'Cache-Control': 'no-cache'
};
const authToken = this.authService.getAccessToken();
if (authToken) {
headers['Authorization'] = 'Bearer ' + authToken;
}
if (!this.abpMultiTenancyService.isEnabled) {
return headers;
}
const multiTenancySide = this.abpMultiTenancyService.multiTenancySide;
if (multiTenancySide == MultiTenancySides.HOST) {
headers['Abp.TenantId'] = undefined;
headers['X-Abp-Host-Tenant-Id'] = impersonating.tenantId;
} else if (multiTenancySide == MultiTenancySides.TENANT) {
headers['Abp.TenantId'] = impersonating.tenantId;
headers['X-Abp-Host-Tenant-Id'] = undefined;
}
return headers;
}
private formatUrl(url: string):