forked from mito-systems/sol-mem-gen
Improve error handling in flux API
This commit is contained in:
parent
41470fc895
commit
2f7fbac703
@ -25,18 +25,19 @@ declare global {
|
||||
// Initialize global quotes service
|
||||
(global as any).quotesService = quotesService
|
||||
|
||||
app.prepare().then(() => {
|
||||
app.prepare().then(async() => {
|
||||
const server = createServer(async (req, res) => {
|
||||
const parsedUrl = parse(req.url!, true);
|
||||
|
||||
handle(req, res, parsedUrl);
|
||||
});
|
||||
|
||||
await quotesService.fetchAndCacheQuotes(); // Initial store
|
||||
|
||||
server.listen(port, () => {
|
||||
console.log(`> Server listening at http://localhost:${port}`);
|
||||
});
|
||||
|
||||
// Initial call and interval setup
|
||||
quotesService.fetchAndCacheQuotes(); // Initial store
|
||||
setInterval(() => quotesService.fetchAndCacheQuotes(), 5 * 60 * 1000); // Update cache every 5 minutes
|
||||
// Interval setup
|
||||
setInterval(async () => await quotesService.fetchAndCacheQuotes(), 5 * 60 * 1000); // Update cache every 5 minutes
|
||||
});
|
||||
|
@ -91,14 +91,17 @@ export async function POST(req: NextRequest): Promise<NextResponse> {
|
||||
|
||||
if (!imageUrl) {
|
||||
console.error('No image URL in response:', result)
|
||||
throw new Error('No image URL in response')
|
||||
return NextResponse.json(
|
||||
{ error: 'No image URL in response: ', result },
|
||||
{ status: 400 }
|
||||
)
|
||||
}
|
||||
|
||||
return NextResponse.json({ imageUrl })
|
||||
} catch (error) {
|
||||
console.error('Flux generation error:', error)
|
||||
return NextResponse.json(
|
||||
{ error: error instanceof Error ? error.message : 'Failed to generate image' },
|
||||
{ error: 'Failed to generate image' },
|
||||
{ status: 500 }
|
||||
)
|
||||
}
|
||||
|
@ -4,8 +4,8 @@ import { NextRequest, NextResponse } from 'next/server';
|
||||
export async function GET(req: NextRequest) {
|
||||
try {
|
||||
const amountOfMTM: BN[] = (global as any).quotesService.getMTMAmountsFor1USDC();
|
||||
const amountOfMTMAsString = amountOfMTM.map(amount => amount.toString());
|
||||
return NextResponse.json(amountOfMTMAsString);
|
||||
const latestMTMAmount = amountOfMTM[amountOfMTM.length - 1].toString();
|
||||
return NextResponse.json(latestMTMAmount);
|
||||
} catch (error) {
|
||||
return NextResponse.json({ error: 'Failed to fetch quotes' }, { status: 500 });
|
||||
}
|
||||
|
@ -26,7 +26,7 @@ const Page: React.FC = (): React.ReactElement => {
|
||||
const data = await response.json();
|
||||
|
||||
// Convert the string back to BN
|
||||
const price = new BN(data[data.length - 1]);
|
||||
const price = new BN(data);
|
||||
setPriceMTMFor1USDC(price);
|
||||
} catch (error) {
|
||||
console.error('Failed to fetch price:', error);
|
||||
|
Loading…
Reference in New Issue
Block a user