@valbuild/shared 0.134.0 → 0.134.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,25 @@
|
|
|
1
1
|
# @valbuild/shared
|
|
2
2
|
|
|
3
|
+
## 0.134.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#709](https://github.com/valbuild/val/pull/709) [`821e789`](https://github.com/valbuild/val/commit/821e789c1af47510af5d23eb96384ff78ddd7646) Thanks [@freekh](https://github.com/freekh)! - Show the reason behind a content-service error instead of just "Internal Server
|
|
8
|
+
Error".
|
|
9
|
+
|
|
10
|
+
`content.val.build` answers a handler that threw with `{ message: "Internal
|
|
11
|
+
Server Error", details: "<the actual cause>" }`. Val was reading `message` and
|
|
12
|
+
dropping `details`, so a failed save put exactly this in front of an editor —
|
|
13
|
+
and the same text in the app's own logs, because Val was relaying it:
|
|
14
|
+
|
|
15
|
+
```json
|
|
16
|
+
{ "type": "patch-error", "message": "Internal Server Error", "errors": { … } }
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
A string `details` is now appended to the message (capped at 500 characters).
|
|
20
|
+
A structured one is not: that is what a _refusal_ carries, and its summary is
|
|
21
|
+
already the message.
|
|
22
|
+
|
|
3
23
|
## 0.134.0
|
|
4
24
|
|
|
5
25
|
### Minor Changes
|
|
@@ -3057,12 +3057,59 @@ var Api = {
|
|
|
3057
3057
|
// `number` is allowed because the client stringifies every query value before it
|
|
3058
3058
|
// goes on the URL (see createValClient), so a numeric param round-trips fine.
|
|
3059
3059
|
|
|
3060
|
+
/**
|
|
3061
|
+
* How long an appended `details` may be before it is cut.
|
|
3062
|
+
*
|
|
3063
|
+
* A thrown DAL error in the content service quotes the whole offending ROW back
|
|
3064
|
+
* — which for a patch is every op the editor just made — so an uncapped append
|
|
3065
|
+
* puts kilobytes of JSON in a dialog. The head is where the cause is; the tail
|
|
3066
|
+
* is the evidence, and it belongs in the service's own logs.
|
|
3067
|
+
*/
|
|
3068
|
+
var MAX_DETAILS_LENGTH = 500;
|
|
3060
3069
|
function getErrorMessageFromUnknownJson(json, fallback) {
|
|
3061
3070
|
if (getSitemapTree._typeof(json) === "object" && json !== null && "message" in json && typeof json.message === "string") {
|
|
3062
|
-
|
|
3071
|
+
var details = detailsOf(json);
|
|
3072
|
+
if (details === null || details === json.message) {
|
|
3073
|
+
return json.message;
|
|
3074
|
+
}
|
|
3075
|
+
return "".concat(json.message, ": ").concat(details);
|
|
3063
3076
|
}
|
|
3064
3077
|
return fallback;
|
|
3065
3078
|
}
|
|
3079
|
+
|
|
3080
|
+
/**
|
|
3081
|
+
* The cause the content service put beside its message, when it wrote one a
|
|
3082
|
+
* person can read.
|
|
3083
|
+
*
|
|
3084
|
+
* `HttpError` in `home` is `{ statusCode, message?, details? }`, and `details`
|
|
3085
|
+
* is filled in two quite different ways. Where a handler REFUSED, it holds the
|
|
3086
|
+
* structured zod error whose summary is already the `message` — repeating it
|
|
3087
|
+
* adds nothing. Where a handler THREW, `sendResult` writes `message:
|
|
3088
|
+
* "Internal Server Error"` and puts the exception's own message in `details` —
|
|
3089
|
+
* so there the message says nothing and the details say everything.
|
|
3090
|
+
*
|
|
3091
|
+
* Which is why the test is the TYPE rather than the status code: a string
|
|
3092
|
+
* `details` is prose meant to be read, an object is a payload meant to be
|
|
3093
|
+
* parsed. This takes the first and leaves the second.
|
|
3094
|
+
*
|
|
3095
|
+
* It was written after an hour was lost to the second case. A patch save
|
|
3096
|
+
* against a content service that threw showed the Studio exactly
|
|
3097
|
+
* `"Internal Server Error"` and nothing else, in a dialog with no other clue,
|
|
3098
|
+
* while the service's answer had been carrying the reason the whole time.
|
|
3099
|
+
*/
|
|
3100
|
+
function detailsOf(json) {
|
|
3101
|
+
if (!("details" in json) || typeof json.details !== "string") {
|
|
3102
|
+
return null;
|
|
3103
|
+
}
|
|
3104
|
+
var details = json.details.trim();
|
|
3105
|
+
if (details === "") {
|
|
3106
|
+
return null;
|
|
3107
|
+
}
|
|
3108
|
+
if (details.length <= MAX_DETAILS_LENGTH) {
|
|
3109
|
+
return details;
|
|
3110
|
+
}
|
|
3111
|
+
return "".concat(details.slice(0, MAX_DETAILS_LENGTH), "\u2026");
|
|
3112
|
+
}
|
|
3066
3113
|
var DEFAULT_ERROR_MESSAGE = "Unknown error with unknown message from server";
|
|
3067
3114
|
|
|
3068
3115
|
var createValClient = function createValClient(host, config // We want to use this in the future
|
|
@@ -3057,12 +3057,59 @@ var Api = {
|
|
|
3057
3057
|
// `number` is allowed because the client stringifies every query value before it
|
|
3058
3058
|
// goes on the URL (see createValClient), so a numeric param round-trips fine.
|
|
3059
3059
|
|
|
3060
|
+
/**
|
|
3061
|
+
* How long an appended `details` may be before it is cut.
|
|
3062
|
+
*
|
|
3063
|
+
* A thrown DAL error in the content service quotes the whole offending ROW back
|
|
3064
|
+
* — which for a patch is every op the editor just made — so an uncapped append
|
|
3065
|
+
* puts kilobytes of JSON in a dialog. The head is where the cause is; the tail
|
|
3066
|
+
* is the evidence, and it belongs in the service's own logs.
|
|
3067
|
+
*/
|
|
3068
|
+
var MAX_DETAILS_LENGTH = 500;
|
|
3060
3069
|
function getErrorMessageFromUnknownJson(json, fallback) {
|
|
3061
3070
|
if (getSitemapTree._typeof(json) === "object" && json !== null && "message" in json && typeof json.message === "string") {
|
|
3062
|
-
|
|
3071
|
+
var details = detailsOf(json);
|
|
3072
|
+
if (details === null || details === json.message) {
|
|
3073
|
+
return json.message;
|
|
3074
|
+
}
|
|
3075
|
+
return "".concat(json.message, ": ").concat(details);
|
|
3063
3076
|
}
|
|
3064
3077
|
return fallback;
|
|
3065
3078
|
}
|
|
3079
|
+
|
|
3080
|
+
/**
|
|
3081
|
+
* The cause the content service put beside its message, when it wrote one a
|
|
3082
|
+
* person can read.
|
|
3083
|
+
*
|
|
3084
|
+
* `HttpError` in `home` is `{ statusCode, message?, details? }`, and `details`
|
|
3085
|
+
* is filled in two quite different ways. Where a handler REFUSED, it holds the
|
|
3086
|
+
* structured zod error whose summary is already the `message` — repeating it
|
|
3087
|
+
* adds nothing. Where a handler THREW, `sendResult` writes `message:
|
|
3088
|
+
* "Internal Server Error"` and puts the exception's own message in `details` —
|
|
3089
|
+
* so there the message says nothing and the details say everything.
|
|
3090
|
+
*
|
|
3091
|
+
* Which is why the test is the TYPE rather than the status code: a string
|
|
3092
|
+
* `details` is prose meant to be read, an object is a payload meant to be
|
|
3093
|
+
* parsed. This takes the first and leaves the second.
|
|
3094
|
+
*
|
|
3095
|
+
* It was written after an hour was lost to the second case. A patch save
|
|
3096
|
+
* against a content service that threw showed the Studio exactly
|
|
3097
|
+
* `"Internal Server Error"` and nothing else, in a dialog with no other clue,
|
|
3098
|
+
* while the service's answer had been carrying the reason the whole time.
|
|
3099
|
+
*/
|
|
3100
|
+
function detailsOf(json) {
|
|
3101
|
+
if (!("details" in json) || typeof json.details !== "string") {
|
|
3102
|
+
return null;
|
|
3103
|
+
}
|
|
3104
|
+
var details = json.details.trim();
|
|
3105
|
+
if (details === "") {
|
|
3106
|
+
return null;
|
|
3107
|
+
}
|
|
3108
|
+
if (details.length <= MAX_DETAILS_LENGTH) {
|
|
3109
|
+
return details;
|
|
3110
|
+
}
|
|
3111
|
+
return "".concat(details.slice(0, MAX_DETAILS_LENGTH), "\u2026");
|
|
3112
|
+
}
|
|
3066
3113
|
var DEFAULT_ERROR_MESSAGE = "Unknown error with unknown message from server";
|
|
3067
3114
|
|
|
3068
3115
|
var createValClient = function createValClient(host, config // We want to use this in the future
|
|
@@ -3050,12 +3050,59 @@ var Api = {
|
|
|
3050
3050
|
// `number` is allowed because the client stringifies every query value before it
|
|
3051
3051
|
// goes on the URL (see createValClient), so a numeric param round-trips fine.
|
|
3052
3052
|
|
|
3053
|
+
/**
|
|
3054
|
+
* How long an appended `details` may be before it is cut.
|
|
3055
|
+
*
|
|
3056
|
+
* A thrown DAL error in the content service quotes the whole offending ROW back
|
|
3057
|
+
* — which for a patch is every op the editor just made — so an uncapped append
|
|
3058
|
+
* puts kilobytes of JSON in a dialog. The head is where the cause is; the tail
|
|
3059
|
+
* is the evidence, and it belongs in the service's own logs.
|
|
3060
|
+
*/
|
|
3061
|
+
var MAX_DETAILS_LENGTH = 500;
|
|
3053
3062
|
function getErrorMessageFromUnknownJson(json, fallback) {
|
|
3054
3063
|
if (_typeof(json) === "object" && json !== null && "message" in json && typeof json.message === "string") {
|
|
3055
|
-
|
|
3064
|
+
var details = detailsOf(json);
|
|
3065
|
+
if (details === null || details === json.message) {
|
|
3066
|
+
return json.message;
|
|
3067
|
+
}
|
|
3068
|
+
return "".concat(json.message, ": ").concat(details);
|
|
3056
3069
|
}
|
|
3057
3070
|
return fallback;
|
|
3058
3071
|
}
|
|
3072
|
+
|
|
3073
|
+
/**
|
|
3074
|
+
* The cause the content service put beside its message, when it wrote one a
|
|
3075
|
+
* person can read.
|
|
3076
|
+
*
|
|
3077
|
+
* `HttpError` in `home` is `{ statusCode, message?, details? }`, and `details`
|
|
3078
|
+
* is filled in two quite different ways. Where a handler REFUSED, it holds the
|
|
3079
|
+
* structured zod error whose summary is already the `message` — repeating it
|
|
3080
|
+
* adds nothing. Where a handler THREW, `sendResult` writes `message:
|
|
3081
|
+
* "Internal Server Error"` and puts the exception's own message in `details` —
|
|
3082
|
+
* so there the message says nothing and the details say everything.
|
|
3083
|
+
*
|
|
3084
|
+
* Which is why the test is the TYPE rather than the status code: a string
|
|
3085
|
+
* `details` is prose meant to be read, an object is a payload meant to be
|
|
3086
|
+
* parsed. This takes the first and leaves the second.
|
|
3087
|
+
*
|
|
3088
|
+
* It was written after an hour was lost to the second case. A patch save
|
|
3089
|
+
* against a content service that threw showed the Studio exactly
|
|
3090
|
+
* `"Internal Server Error"` and nothing else, in a dialog with no other clue,
|
|
3091
|
+
* while the service's answer had been carrying the reason the whole time.
|
|
3092
|
+
*/
|
|
3093
|
+
function detailsOf(json) {
|
|
3094
|
+
if (!("details" in json) || typeof json.details !== "string") {
|
|
3095
|
+
return null;
|
|
3096
|
+
}
|
|
3097
|
+
var details = json.details.trim();
|
|
3098
|
+
if (details === "") {
|
|
3099
|
+
return null;
|
|
3100
|
+
}
|
|
3101
|
+
if (details.length <= MAX_DETAILS_LENGTH) {
|
|
3102
|
+
return details;
|
|
3103
|
+
}
|
|
3104
|
+
return "".concat(details.slice(0, MAX_DETAILS_LENGTH), "\u2026");
|
|
3105
|
+
}
|
|
3059
3106
|
var DEFAULT_ERROR_MESSAGE = "Unknown error with unknown message from server";
|
|
3060
3107
|
|
|
3061
3108
|
var createValClient = function createValClient(host, config // We want to use this in the future
|