All practice tasks

Coding (Platform)

Canonical error envelope

fastify · Easy · error contract

Several route handlers expose different error shapes. Clients cannot distinguish a validation error from a retryable dependency failure without parsing prose.

Task

Normalize a service failure into the public error envelope without exposing internal messages.

Contract

Input is {kind,field,retryAfterMs,requestId}. Return {status,body,headers}. Supported kinds are validation, unauthorized, conflict, dependency and unknown.

Acceptance criteria

  • Map each known kind to its documented status and code.
  • Include field only for validation.
  • Round retry-after up to whole seconds for dependency failures.
  • Expose requestId but never internal text.

Constraints

  • Do not mutate caller-owned input.
  • Keep the supplied framework adapter and public contract unchanged.
  • Add candidate tests for at least one boundary not covered by the public cases.

Editable files

  • src/repair.js — Task-specific state or service boundary
  • tests/candidate.test.js — Candidate-authored regression

What this task practices

Canonical error envelope is a coding (platform) interview exercise that trains prompt interpretation, explicit assumptions, a concrete response, and a clear explanation of tradeoffs. The catalog marks it as easy difficulty. It focuses on State Modeling, Regression Testing, Technical Reasoning. The signed-in workspace provides the tools for the round and evaluates the attempt against task-specific criteria. Reference solutions, hidden checks, evaluator instructions, and candidate work remain private.

Sign in to startThe workspace and evaluation open after sign in.