errors: typed helpers for every documented error type
AlexaErrors has a helper for each of the 73 types of the table on alexa-errorresponse.html, named after the type in camel case: 63 take the message only, 10 take the payload fields their page documents. A field the page requires (reason, currentDeviceMode, currentChargeState, resourceType) is a required argument, so leaving it out does not compile; from JavaScript the helper throws a TypeError that lists the values. validRange is optional, as the page says, and has both ends when given. temperatureOutOfRange and setpointsTooClose stay as shorter names. The helpers are compared with the 15 examples of the four error pages. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
parent
4a3dd81bcf
commit
94b13f733a
36 changed files with 874 additions and 138 deletions
18
test/fixtures/types.ts
vendored
18
test/fixtures/types.ts
vendored
|
|
@ -156,6 +156,24 @@ const changedNames: string[] = report.event.payload.change.properties.map((prope
|
|||
messages.deferredResponse({ endpointId: "lamp-1", correlationToken: "ct" }).context;
|
||||
// @ts-expect-error the range is two numbers
|
||||
AlexaErrors.valueOutOfRange("too high", { minimumValue: 1 });
|
||||
// @ts-expect-error a temperature has a scale
|
||||
AlexaErrors.temperatureValueOutOfRange("too cold", { minimumValue: 15, maximumValue: 30 });
|
||||
// @ts-expect-error the reason is required
|
||||
AlexaErrors.endpointControlUnavailable("no connectivity package");
|
||||
// @ts-expect-error the mode is one of the page's
|
||||
AlexaErrors.notSupportedInCurrentMode("the lamp shows a color", "PARTY");
|
||||
// @ts-expect-error the state of the battery is required
|
||||
AlexaErrors.notSupportedWithCurrentBatteryChargeState("charging");
|
||||
// @ts-expect-error the resource is required
|
||||
AlexaErrors.insufficientResource("the tank is empty");
|
||||
// @ts-expect-error a type without fields takes the message only
|
||||
AlexaErrors.thermostatIsOff("the thermostat is off", { validRange: { minimumValue: 1, maximumValue: 2 } });
|
||||
// @ts-expect-error not a type of the table
|
||||
AlexaErrors.thermostatIsOn("the thermostat is on");
|
||||
const plainErrors: string[] = [
|
||||
AlexaErrors.endpointUnreachable("the lamp does not answer"), AlexaErrors.obstacleDetected("something is in the way"),
|
||||
AlexaErrors.valueOutOfRange("too high"), AlexaErrors.maintenanceRequired("the bin is full", "EMPTY_BIN"),
|
||||
].map((error) => error.type);
|
||||
const errorNamespace: string = AlexaErrors.setpointsTooClose("too close", { value: 2, scale: "CELSIUS" }).namespace;
|
||||
|
||||
// Handlers: the directives of the interface by name, the payload of each typed by its descriptor
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue