503 Service Unavailable
The server is currently unable to handle the request due to temporary overloading or maintenance. Try again later.
When and Why to Use It
Section titled “When and Why to Use It”Use this when you are intentionally taking the service offline for patching. Tell load balancers you are under maintenance so they can redirect traffic.
Usage Examples
Section titled “Usage Examples”import { HttpException, get } from 'shokupan';
export const checkout = get('/checkout', () => { // Check a global or env flag if (process.env.MAINTENANCE_MODE === 'true') { throw new HttpException('Store is closed for maintenance', 503); }
// ... proceed with checkout});import { Controller, Get, HttpException } from 'shokupan';
@Controller('/api')export class StoreController { @Get('/checkout') checkout() { if (process.env.MAINTENANCE_MODE === 'true') { throw new HttpException('Store is closed for maintenance', 503); }
// ... proceed with checkout }}import express from 'express';const app = express();
// You can apply this as global middleware!app.use((req, res, next) => { if (process.env.MAINTENANCE_MODE === 'true') { res.set('Retry-After', '3600'); // 1 hour return res.status(503).json({ error: 'Maintenance Mode' }); } next();});
app.get('/checkout', (req, res) => { // ... proceed with checkout});import { Controller, Get, ServiceUnavailableException } from '@nestjs/common';
@Controller('store')export class StoreController { @Get('checkout') checkout() { if (process.env.MAINTENANCE_MODE === 'true') { throw new ServiceUnavailableException('Store is closed for maintenance'); }
// ... proceed with checkout }}import Koa from 'koa';const app = new Koa();
// Global middlewareapp.use(async (ctx, next) => { if (process.env.MAINTENANCE_MODE === 'true') { ctx.set('Retry-After', '3600'); ctx.status = 503; ctx.body = { error: 'Maintenance Mode' }; return; } await next();});