2022-07-11 04:09:46 +00:00
|
|
|
import { ENV_CONFIG } from './envs/constants'
|
2022-07-10 22:03:15 +00:00
|
|
|
|
|
|
|
export class APIError extends Error {
|
|
|
|
code: number
|
|
|
|
details?: unknown
|
|
|
|
constructor(code: number, message: string, details?: unknown) {
|
|
|
|
super(message)
|
|
|
|
this.code = code
|
|
|
|
this.name = 'APIError'
|
|
|
|
this.details = details
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export function getFunctionUrl(name: string) {
|
2022-07-24 07:26:38 +00:00
|
|
|
if (process.env.NEXT_PUBLIC_FUNCTIONS_URL) {
|
|
|
|
return `${process.env.NEXT_PUBLIC_FUNCTIONS_URL}/${name}`
|
|
|
|
} else if (process.env.NEXT_PUBLIC_FIREBASE_EMULATE) {
|
2022-07-10 22:03:15 +00:00
|
|
|
const { projectId, region } = ENV_CONFIG.firebaseConfig
|
|
|
|
return `http://localhost:5001/${projectId}/${region}/${name}`
|
|
|
|
} else {
|
|
|
|
const { cloudRunId, cloudRunRegion } = ENV_CONFIG
|
|
|
|
return `https://${name}-${cloudRunId}-${cloudRunRegion}.a.run.app`
|
|
|
|
}
|
|
|
|
}
|