You've already forked AstralRinth
forked from didirus/AstralRinth
Error on state fail in prod and log endpoint errors (#5167)
* Error on state fail in prod and log endpoint errors * brint back eslint suppress * lint
This commit is contained in:
@@ -166,6 +166,17 @@ export default defineNuxtConfig({
|
|||||||
|
|
||||||
await fs.writeFile('./src/generated/state.json', JSON.stringify(state))
|
await fs.writeFile('./src/generated/state.json', JSON.stringify(state))
|
||||||
|
|
||||||
|
// throw if errors and building for prod (preview & staging allowed to have errors)
|
||||||
|
if (
|
||||||
|
process.env.BUILD_ENV === 'production' &&
|
||||||
|
process.env.PREVIEW !== 'true' &&
|
||||||
|
generatedState.errors.length > 0
|
||||||
|
) {
|
||||||
|
throw new Error(
|
||||||
|
`Production build failed: State generation encountered errors. Error codes: ${JSON.stringify(generatedState.errors)}; API URL: ${API_URL}`,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
console.log('Tags generated!')
|
console.log('Tags generated!')
|
||||||
|
|
||||||
const robotsContent =
|
const robotsContent =
|
||||||
|
|||||||
@@ -20,9 +20,9 @@ export class LabrinthStateModule extends AbstractModule {
|
|||||||
public async build(): Promise<Labrinth.State.GeneratedState> {
|
public async build(): Promise<Labrinth.State.GeneratedState> {
|
||||||
const errors: unknown[] = []
|
const errors: unknown[] = []
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
const handleError = (err: any, defaultValue: any) => {
|
const handleError = (err: any, defaultValue: any, endpoint: string) => {
|
||||||
console.error('Error fetching state data:', err)
|
console.error('Error fetching state data:', err)
|
||||||
errors.push(err)
|
errors.push({ endpoint, error: err })
|
||||||
return defaultValue
|
return defaultValue
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -49,31 +49,31 @@ export class LabrinthStateModule extends AbstractModule {
|
|||||||
version: 2,
|
version: 2,
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
})
|
})
|
||||||
.catch((err) => handleError(err, [])),
|
.catch((err) => handleError(err, [], '/v2/tag/category')),
|
||||||
this.client
|
this.client
|
||||||
.request<Labrinth.Tags.v2.Loader[]>('/tag/loader', {
|
.request<Labrinth.Tags.v2.Loader[]>('/tag/loader', {
|
||||||
api: 'labrinth',
|
api: 'labrinth',
|
||||||
version: 2,
|
version: 2,
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
})
|
})
|
||||||
.catch((err) => handleError(err, [])),
|
.catch((err) => handleError(err, [], '/v2/tag/loader')),
|
||||||
this.client
|
this.client
|
||||||
.request<Labrinth.Tags.v2.GameVersion[]>('/tag/game_version', {
|
.request<Labrinth.Tags.v2.GameVersion[]>('/tag/game_version', {
|
||||||
api: 'labrinth',
|
api: 'labrinth',
|
||||||
version: 2,
|
version: 2,
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
})
|
})
|
||||||
.catch((err) => handleError(err, [])),
|
.catch((err) => handleError(err, [], '/v2/tag/game_version')),
|
||||||
this.client
|
this.client
|
||||||
.request<Labrinth.Tags.v2.DonationPlatform[]>('/tag/donation_platform', {
|
.request<Labrinth.Tags.v2.DonationPlatform[]>('/tag/donation_platform', {
|
||||||
api: 'labrinth',
|
api: 'labrinth',
|
||||||
version: 2,
|
version: 2,
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
})
|
})
|
||||||
.catch((err) => handleError(err, [])),
|
.catch((err) => handleError(err, [], '/v2/tag/donation_platform')),
|
||||||
this.client
|
this.client
|
||||||
.request<string[]>('/tag/report_type', { api: 'labrinth', version: 2, method: 'GET' })
|
.request<string[]>('/tag/report_type', { api: 'labrinth', version: 2, method: 'GET' })
|
||||||
.catch((err) => handleError(err, [])),
|
.catch((err) => handleError(err, [], '/v2/tag/report_type')),
|
||||||
|
|
||||||
// Homepage data
|
// Homepage data
|
||||||
this.client
|
this.client
|
||||||
@@ -83,7 +83,7 @@ export class LabrinthStateModule extends AbstractModule {
|
|||||||
method: 'GET',
|
method: 'GET',
|
||||||
params: { count: '60' },
|
params: { count: '60' },
|
||||||
})
|
})
|
||||||
.catch((err) => handleError(err, [])),
|
.catch((err) => handleError(err, [], '/v2/projects_random')),
|
||||||
this.client
|
this.client
|
||||||
.request<Labrinth.Search.v2.SearchResults>('/search', {
|
.request<Labrinth.Search.v2.SearchResults>('/search', {
|
||||||
api: 'labrinth',
|
api: 'labrinth',
|
||||||
@@ -91,7 +91,7 @@ export class LabrinthStateModule extends AbstractModule {
|
|||||||
method: 'GET',
|
method: 'GET',
|
||||||
params: { limit: '3', query: 'leave', index: 'relevance' },
|
params: { limit: '3', query: 'leave', index: 'relevance' },
|
||||||
})
|
})
|
||||||
.catch((err) => handleError(err, {} as Labrinth.Search.v2.SearchResults)),
|
.catch((err) => handleError(err, {} as Labrinth.Search.v2.SearchResults, '/v2/search')),
|
||||||
this.client
|
this.client
|
||||||
.request<Labrinth.Search.v2.SearchResults>('/search', {
|
.request<Labrinth.Search.v2.SearchResults>('/search', {
|
||||||
api: 'labrinth',
|
api: 'labrinth',
|
||||||
@@ -99,22 +99,24 @@ export class LabrinthStateModule extends AbstractModule {
|
|||||||
method: 'GET',
|
method: 'GET',
|
||||||
params: { limit: '3', query: '', index: 'updated' },
|
params: { limit: '3', query: '', index: 'updated' },
|
||||||
})
|
})
|
||||||
.catch((err) => handleError(err, {} as Labrinth.Search.v2.SearchResults)),
|
.catch((err) => handleError(err, {} as Labrinth.Search.v2.SearchResults, '/v2/search')),
|
||||||
|
|
||||||
// Internal billing/mural endpoints
|
// Internal billing/mural endpoints
|
||||||
this.client.labrinth.billing_internal.getProducts().catch((err) => handleError(err, [])),
|
this.client.labrinth.billing_internal
|
||||||
|
.getProducts()
|
||||||
|
.catch((err) => handleError(err, [], '/_internal/billing/products')),
|
||||||
this.client
|
this.client
|
||||||
.request<{ bankDetails: Record<string, { bankNames: string[] }> }>('/mural/bank-details', {
|
.request<{ bankDetails: Record<string, { bankNames: string[] }> }>('/mural/bank-details', {
|
||||||
api: 'labrinth',
|
api: 'labrinth',
|
||||||
version: 'internal',
|
version: 'internal',
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
})
|
})
|
||||||
.catch((err) => handleError(err, null)),
|
.catch((err) => handleError(err, null, '/_internal/mural/bank-details')),
|
||||||
|
|
||||||
// ISO3166 country and subdivision data
|
// ISO3166 country and subdivision data
|
||||||
this.client.iso3166.data
|
this.client.iso3166.data
|
||||||
.build()
|
.build()
|
||||||
.catch((err) => handleError(err, { countries: [], subdivisions: {} })),
|
.catch((err) => handleError(err, { countries: [], subdivisions: {} }, 'iso3166/data')),
|
||||||
|
|
||||||
// Payout methods for tremendous ID mapping
|
// Payout methods for tremendous ID mapping
|
||||||
this.client
|
this.client
|
||||||
@@ -123,7 +125,7 @@ export class LabrinthStateModule extends AbstractModule {
|
|||||||
version: 3,
|
version: 3,
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
})
|
})
|
||||||
.catch((err) => handleError(err, [])),
|
.catch((err) => handleError(err, [], '/v3/payout/methods')),
|
||||||
])
|
])
|
||||||
|
|
||||||
const tremendousIdMap = Object.fromEntries(
|
const tremendousIdMap = Object.fromEntries(
|
||||||
|
|||||||
Reference in New Issue
Block a user