nohead 0.20.0 → 0.22.0
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +11 -0
- data/README.md +7 -4
- data/lib/nohead/errors.rb +11 -1
- data/lib/nohead/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 1635a80aebc12509563ede6922a27454a90929d9b77095ff3fa0f44d8e265c1c
|
|
4
|
+
data.tar.gz: 7102d397fab4069d4390d839537ad46b5d62cf22b8dda241e7778133127304e3
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: ef32fd9f6368e9048b00c05eeef555502c1c5d7c662102dc090fb3b3118d0f7350ebed31a5bc159ca7d8073a3b795bf5de1145afd1b506fdebdaa62116a39cd6
|
|
7
|
+
data.tar.gz: c358478c9b13b88326a2e952ffb51def1900250e8d6773c39971e4eea78d49e48444e859796d4ea67a12cf0c6d00ae581267dcedb5d8bd4ab8a7cdc2a2e5b442
|
data/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,17 @@ Changes to the `nohead` gem that you can notice. Versions follow
|
|
|
5
5
|
releases; a change that could break your code is a major one. Each release's
|
|
6
6
|
section is its GitHub release's notes.
|
|
7
7
|
|
|
8
|
+
## 0.22.0
|
|
9
|
+
|
|
10
|
+
- `ValidationError#field_errors`: the first message for each field, by its
|
|
11
|
+
key (`{ "email" => "is required" }`), to show beside a form's fields.
|
|
12
|
+
Details without a field are left out; `details` keeps every code.
|
|
13
|
+
|
|
14
|
+
## 0.21.0
|
|
15
|
+
|
|
16
|
+
- Nothing changed in the gem: the SDKs share one version, and this release
|
|
17
|
+
matches the TypeScript SDK's 0.21.0, whose public search changed.
|
|
18
|
+
|
|
8
19
|
## 0.20.0
|
|
9
20
|
|
|
10
21
|
- Nothing changed in the gem: the SDKs share one version, and this release
|
data/README.md
CHANGED
|
@@ -179,7 +179,7 @@ Every error is a `Nohead::Error`. API errors are `Nohead::APIError`s with `statu
|
|
|
179
179
|
| `NotFoundError` | 404 |
|
|
180
180
|
| `ConflictError` | 409 |
|
|
181
181
|
| `PreconditionFailedError` | 412 (`current_revision`) |
|
|
182
|
-
| `ValidationError` | 422 |
|
|
182
|
+
| `ValidationError` | 422 (`field_errors`) |
|
|
183
183
|
| `RateLimitError` | 429 (`retry_after`) |
|
|
184
184
|
| `InternalServerError` | 500 and other 5xx |
|
|
185
185
|
| `ServiceUnavailableError` | 503 |
|
|
@@ -192,11 +192,14 @@ Other errors:
|
|
|
192
192
|
- `Nohead::UploadError`
|
|
193
193
|
- `Nohead::WebhookVerificationError`
|
|
194
194
|
|
|
195
|
+
A form that writes a record shows a `ValidationError`'s `field_errors` beside its fields: the first message for each field, by its key. `details` has every problem with its `code` (`required`, `taken`), for words of your own.
|
|
196
|
+
|
|
195
197
|
```ruby
|
|
196
|
-
|
|
197
|
-
nohead.records.create("
|
|
198
|
+
def apply(name, email)
|
|
199
|
+
nohead.records.create("applications", data: { name: name, email: email })
|
|
200
|
+
{ sent: true }
|
|
198
201
|
rescue Nohead::ValidationError => e
|
|
199
|
-
|
|
202
|
+
{ sent: false, errors: e.field_errors } # { "email" => "is required" }
|
|
200
203
|
end
|
|
201
204
|
```
|
|
202
205
|
|
data/lib/nohead/errors.rb
CHANGED
|
@@ -67,7 +67,17 @@ module Nohead
|
|
|
67
67
|
end
|
|
68
68
|
end
|
|
69
69
|
|
|
70
|
-
class ValidationError < APIError
|
|
70
|
+
class ValidationError < APIError
|
|
71
|
+
# The first message for each field, by its key: { "title" => "is required" },
|
|
72
|
+
# to show beside a form's fields. Details without a field are left out;
|
|
73
|
+
# `details` keeps their codes.
|
|
74
|
+
def field_errors
|
|
75
|
+
details.each_with_object({}) do |detail, errors|
|
|
76
|
+
field = detail["field"]
|
|
77
|
+
errors[field] = detail["message"] unless field.to_s.empty? || errors.key?(field)
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
end
|
|
71
81
|
|
|
72
82
|
class RateLimitError < APIError
|
|
73
83
|
# Seconds to wait before retrying, from `Retry-After`.
|
data/lib/nohead/version.rb
CHANGED