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

Most upvoted comments

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. Ie

invalid(420, { status: "Too high" });

or

failed({ status: "Something broke }); // returns a 500 

I like fail (failed feels wrong – it would imply we should also have errored and redirected, which sound terrible). I like nope 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 fun

it just feels that

return failure(...

is more natural than

return fail(...

Rename error to exception and invalid to error. 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.

  • it feels a little cryptic
  • it is kind of informal
  • is used by hapi and it might bring confusion over time

So, I would rather recommend a more generic failure(status, data) instead of fail, failed

return failure(status, data) seems more natural

I like invalid, because it’s a very good fit for 90% of use cases.