Repository navigation
Description
Why?
Since cloud-registry 0.4.0, apps must react differently to 401 (log in; e.g., on deployments that require login for reads, elixir-cloud-aai/cloud-registry#168) and 403 (the user lacks a role on the service, elixir-cloud-aai/cloud-registry#62). Users also need the reason for a failed request: the registry explains every error as problem details (title, status, detail, plus serviceId for duplicates), and 400s name the field, e.g. "URLs in 'organization.url' must use one of these schemes: 'http', 'https'."
RestCloudRegistryProvider throws a plain Error with a message built from response.statusText and never reads the body. Apps can't tell the status from it, and statusText is empty over HTTP/2, so the message reads "Failed to create service: ". ecc-service-create-failed passes that message on, so users of the create component don't learn why a registration failed.
The Cloud Registry UI works around this in its own copy of the provider (src/lib/authenticated-cloud-registry.ts): it reads the JSON body, uses detail as the message, and adds status, title, detail and serviceId to the error (elixir-cloud-aai/cloud-registry-ui#5, elixir-cloud-aai/cloud-registry-ui#11).
What?
- On
!response.ok, tryresponse.json()whatever the content type (alsoapplication/problem+json; a proxy may send HTML), and usedetail(elsemessage) as the error message; fall back to the status ifstatusTextis empty, e.g. "Request failed (400)". - Throw an error class, e.g.,
CloudRegistryError extends Error, withstatus,title,detailandserviceId, from all provider methods. Export it. - Optionally, emit
statusin the*-failedevents of the components (e.g.,ecc-service-create-failed), next toerror.
Acceptance criteria
- Apps can tell
401from403(and other statuses) for every provider call. - A failed registration in the create component reports the registry's
detail.
Notes: highlighting the field named in a 400 inside the create form is tracked in #453.
Activity