File size: 1,427 Bytes
1477a90 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | namespace Shared;
/**
* Shared properties for inline errors returned inside a 2xx response.
*
* Use for partially successful responses (e.g. per-item failures alongside
* a `data` array) or for pre-flight findings on resources that are not yet
* finalized (e.g. validation errors on a draft resource).
*
* This is **not** an RFC-7807 problem detail. RFC-7807 covers errors that
* fail the whole request; inline errors live as fields on the response or
* resource model.
*
* Compose with `is` and add domain-specific identifying fields as needed:
*
* ```tsp
* @friendlyName("MyOperationError")
* model MyOperationError is Shared.BaseError<MyOperationErrorCode> {
* // domain-specific identifiers, e.g. the input that produced the error
* subject?: string;
* }
* ```
*
* `T` is the type of the `code` field. Prefer a domain-scoped enum with an
* `Unknown: "unknown"` zero member so codes stay discoverable and stable.
* Use `string` only when the set of codes is open-ended.
*/
@friendlyName("BaseError")
model BaseError<T> {
/**
* Machine-readable error code.
*/
@visibility(Lifecycle.Read)
@summary("Code")
code: T;
/**
* Human-readable description of the error.
*/
@visibility(Lifecycle.Read)
@summary("Message")
message: string;
/**
* Additional structured context.
*/
@visibility(Lifecycle.Read)
@summary("Attributes")
attributes?: Record<unknown>;
}
|