kit: Rename `invalid` to... something else?
Describe the problem
One side-note from #7956: invalid(422, {...})
is natural, but invalid(500, {...})
— which you need to do in order to show inline error UI along with repopulated form values — feels a bit weird. The error isn’t that the data was invalid, it’s that something went wrong on the back end.
Describe the proposed solution
Rename it to something that covers both 4xx and 5xx errors:
fail(status, data)
failed(status, data)
nope(status, data)
Suggestions welcome. (Note that we can’t return error(status, data)
because data
must conform to App.Error
in that case.
Alternatives considered
No response
Importance
nice to have
Additional Information
No response
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 24 (10 by maintainers)
Commits related to this issue
- rename invalid() and ValidationError - closes #7982 — committed to sveltejs/kit by Rich-Harris 2 years ago
- [breaking] rename `invalid(...)` and `ValidationError` (#8012) * rename invalid() and ValidationError - closes #7982 * help people migrate — committed to sveltejs/kit by Rich-Harris 2 years ago
Boom(status, data)
You could keep invalid as it is, but add a
failed()
which took only the error data, and returned a 500 for you. Ieor
I like
fail
(failed
feels wrong – it would imply we should also haveerrored
andredirected
, which sound terrible). I likenope
most of all, but I also know the serious-minded folk would hate it. 😆+1 for
failed(status, data)
how about
reject(status, data)
+1 for
nope
makes coding a bit more funit just feels that
is more natural than
Rename
error
toexception
andinvalid
toerror
. The migration would be funny 🤣On a serious note, of the suggestions, I like
failure
the best.on a second thought, I kind of regret the
boom
proposal due to some reasons.So, I would rather recommend a more generic
failure(status, data)
instead offail
,failed
return failure(status, data)
seems more naturalI like
invalid
, because it’s a very good fit for 90% of use cases.