CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl-labs/express-error-handling

Production error handling for Express APIs — error middleware, async wrappers,

89

2.02x
Quality

86%

Does it follow best practices?

Impact

97%

2.02x

Average score across 4 eval scenarios

SecuritybySnyk

Passed

No known issues

Overview
Quality
Evals
Security
Files

task.mdevals/scenario-4/

Build a Weather Proxy API

Problem/Feature Description

Build an Express TypeScript API that fetches weather data from an external service and returns it to clients.

Endpoints:

  • GET /api/weather/:city -- returns current weather for the specified city

Use this simulated external service client (create it as src/weather-client.ts):

// src/weather-client.ts
export interface WeatherData {
  city: string;
  temperature: number;
  conditions: string;
  humidity: number;
}

export async function fetchWeather(city: string): Promise<WeatherData> {
  await new Promise(r => setTimeout(r, 100));

  if (city === 'timeout-city') throw new Error('ETIMEDOUT');
  if (city === 'down-city') {
    const err: any = new Error('Service temporarily unavailable');
    err.status = 503;
    throw err;
  }
  if (city === 'unknown-city') throw new Error('City not found in weather database');

  return {
    city,
    temperature: Math.round(15 + Math.random() * 20),
    conditions: ['sunny', 'cloudy', 'rainy', 'partly cloudy'][Math.floor(Math.random() * 4)],
    humidity: Math.round(30 + Math.random() * 50),
  };
}

The API will be consumed by a mobile app, so responses should always be JSON.

Output Specification

Produce:

  • src/weather-client.ts -- the external service client (copy from above)
  • src/server.ts -- server entry point
  • src/app.ts -- Express application setup
  • src/routes/weather.ts -- route handler
  • package.json -- with dependencies

You may create additional files as needed.

evals

tile.json