Fix some TS errors and type API errors
This commit is contained in:
parent
7a437aad04
commit
20384673f2
|
@ -6,6 +6,7 @@ import {
|
|||
APICallConfig,
|
||||
BaseAPIClient,
|
||||
Headers,
|
||||
APIError,
|
||||
} from "./types"
|
||||
import { Helpers } from "@budibase/bbui"
|
||||
import { Header } from "@budibase/shared-core"
|
||||
|
@ -64,7 +65,7 @@ export const createAPIClient = (config: APIClientConfig = {}): APIClient => {
|
|||
response: Response,
|
||||
method: HTTPMethod,
|
||||
suppressErrors = false
|
||||
) => {
|
||||
): Promise<APIError> => {
|
||||
// Try to read a message from the error
|
||||
let message = response.statusText
|
||||
let json: any = null
|
||||
|
@ -90,7 +91,11 @@ export const createAPIClient = (config: APIClientConfig = {}): APIClient => {
|
|||
}
|
||||
|
||||
// Generates an error object from a string
|
||||
const makeError = (message: string, url?: string, method?: HTTPMethod) => {
|
||||
const makeError = (
|
||||
message: string,
|
||||
url?: string,
|
||||
method?: HTTPMethod
|
||||
): APIError => {
|
||||
return {
|
||||
message,
|
||||
json: null,
|
||||
|
@ -98,6 +103,7 @@ export const createAPIClient = (config: APIClientConfig = {}): APIClient => {
|
|||
url: url,
|
||||
method: method,
|
||||
handled: true,
|
||||
suppressErrors: false,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -11,10 +11,10 @@ import { BaseAPIClient } from "./types"
|
|||
export interface LicensingEndpoints {
|
||||
activateLicenseKey: (licenseKey: string) => Promise<void>
|
||||
deleteLicenseKey: () => Promise<void>
|
||||
getLicenseKey: () => Promise<GetLicenseKeyResponse>
|
||||
getLicenseKey: () => Promise<GetLicenseKeyResponse | void>
|
||||
activateOfflineLicense: (offlineLicenseToken: string) => Promise<void>
|
||||
deleteOfflineLicense: () => Promise<void>
|
||||
getOfflineLicense: () => Promise<GetOfflineLicenseTokenResponse>
|
||||
getOfflineLicense: () => Promise<GetOfflineLicenseTokenResponse | void>
|
||||
getOfflineLicenseIdentifier: () => Promise<GetOfflineIdentifierResponse>
|
||||
refreshLicense: () => Promise<void>
|
||||
getQuotaUsage: () => Promise<QuotaUsage>
|
||||
|
@ -24,7 +24,6 @@ export const buildLicensingEndpoints = (
|
|||
API: BaseAPIClient
|
||||
): LicensingEndpoints => ({
|
||||
// LICENSE KEY
|
||||
|
||||
activateLicenseKey: async licenseKey => {
|
||||
return API.post<ActivateLicenseKeyRequest>({
|
||||
url: `/api/global/license/key`,
|
||||
|
@ -49,7 +48,6 @@ export const buildLicensingEndpoints = (
|
|||
},
|
||||
|
||||
// OFFLINE LICENSE
|
||||
|
||||
activateOfflineLicense: async offlineLicenseToken => {
|
||||
return API.post<ActivateOfflineLicenseTokenRequest>({
|
||||
url: "/api/global/license/offline",
|
||||
|
|
|
@ -73,6 +73,16 @@ export type BaseAPIClient = {
|
|||
getAppID: () => string
|
||||
}
|
||||
|
||||
export type APIError = {
|
||||
message?: string
|
||||
json: any
|
||||
status: number
|
||||
url: string
|
||||
method: HTTPMethod
|
||||
handled: boolean
|
||||
suppressErrors: boolean
|
||||
}
|
||||
|
||||
export type APIClient = BaseAPIClient &
|
||||
AIEndpoints &
|
||||
AnalyticsEndpoints &
|
||||
|
@ -89,4 +99,4 @@ export type APIClient = BaseAPIClient &
|
|||
FlagEndpoints &
|
||||
GroupEndpoints &
|
||||
LayoutEndpoints &
|
||||
LicensingEndpoints
|
||||
LicensingEndpoints & { [key: string]: any }
|
||||
|
|
Loading…
Reference in New Issue