-
-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Rename invalid
to... something else?
#7982
Comments
|
|
I like |
+1 for |
You could keep invalid as it is, but add a
or
|
on a second thought, I kind of regret the
So, I would rather recommend a more generic
|
Really though, I like either Alternatively, I could see changing |
And while we 're at it, may I boldly suggest we revisit the naming for validationError, since this could also be an |
OK, I am going to shut up now :) |
Keep
is IMO bad UX and bad DX. The fact that 400 Bad Request and 403 Forbidden share a 4 is academic -- what matters is the difference in the business logic. |
|
I like |
Actually, there is one more aspect to this... The problem is that So, maybe it would be better to keep the This way, the following code would be much more self explanatory and a pleasure to read, leaving no room for misunderstanding. import { invalid, failure } from '@sveltejs/kit';
export const actions = {
setName: async ({ request }) => {
const data = await request.formData();
const name = data.get('name');
if (!name) {
return invalid(400, { name, missing: true });
}
try {
result = await postToExternalAPI(name);
} catch(error) {
return failure(504, {name, message: 'Upstream server coul not be reached. Try again later'});
}
return { success: true };
}
} |
+1 for |
Considering 4xx and 5xx status codes being for all client and server Among many funny or fancy options, i think a single synonym stands out: |
I prefer |
how about |
Rename On a serious note, of the suggestions, I like |
|
Opened a PR that renames Having gone through the process of updating the code, I'm convinced that this is the right move even if it's a late breaking change. Another couple of reasons presented themselves:
*if someone wanted to be persnickity they could challenge the notion that 'error' is a verb, but I think it's used as a verb often enough in programming that I can claim it with a straight face |
Still not fully convinced. In the ActionResult example I now have a harder time to distinguish between |
it just feels that return failure(... is more natural than return fail(... |
I like this return failure(status, data) or something shorter return failed(status, data) And I agree that invalid is Ok for 4xx, but it doesn't match anything with 5xx. |
* rename invalid() and ValidationError - closes #7982 * help people migrate
glad you picked a verb :D |
Describe the problem
One side-note from #7956:
invalid(422, {...})
is natural, butinvalid(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)
becausedata
must conform toApp.Error
in that case.Alternatives considered
No response
Importance
nice to have
Additional Information
No response
The text was updated successfully, but these errors were encountered: