Give every JSON answer @meta, errors included (closes #201)
check / check (push) Canceled after 0s
check / check (push) Canceled after 0s
A panic in a JSON route's handler answered 500 with an empty body, because the router's recoverer sits outside the middleware that adds `@meta`. `JSONValidationMiddleware` now wraps the handler in the same recoverer, and answers the panic with the JSON error body. A method that `/status.json` or the health check does not take got chi's empty 405. Each such method now goes to the JSON 405 that the routes under `/api/v1` and `/ip` give. The home page's IP lookup card showed only the answer's `data`. It now shows the whole answer, `@meta` included. A table test checks `@meta` on every JSON route, in its successes and its errors. Model: opus-5-5
This commit is contained in:
@@ -714,7 +714,8 @@
|
||||
});
|
||||
});
|
||||
|
||||
// IP lookup
|
||||
// IP lookup: show the whole JSON answer, its @meta and an error answer
|
||||
// included, as the IP information API card does.
|
||||
document.getElementById('ip-form').addEventListener('submit', function(e) {
|
||||
e.preventDefault();
|
||||
const ip = document.getElementById('ip-input').value.trim();
|
||||
@@ -730,18 +731,11 @@
|
||||
|
||||
fetch('/ip/' + encodeURIComponent(ip))
|
||||
.then(response => response.json())
|
||||
.then(response => {
|
||||
contentEl.classList.remove('loading');
|
||||
if (response.status === 'error') {
|
||||
contentEl.className = 'error';
|
||||
contentEl.textContent = 'Error: ' + response.error.msg;
|
||||
} else {
|
||||
contentEl.className = '';
|
||||
contentEl.textContent = JSON.stringify(response.data, null, 2);
|
||||
}
|
||||
.then(answer => {
|
||||
contentEl.className = '';
|
||||
contentEl.textContent = JSON.stringify(answer, null, 2);
|
||||
})
|
||||
.catch(error => {
|
||||
contentEl.classList.remove('loading');
|
||||
contentEl.className = 'error';
|
||||
contentEl.textContent = 'Error: ' + error.message;
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user