Releases: TheEdoRan/next-safe-action
v7.9.6
v7.9.5
v7.9.4
v7.9.3
v7.9.3-beta.1
7.9.3-beta.1 (2024-09-13)
Bug Fixes
- export
SafeActionClient
type to make it portable (#267) (d2d7bdd), closes /typescript.tv/errors/#ts2742
v7.9.2
v7.9.1
v7.9.1-beta.1
7.9.1-beta.1 (2024-09-07)
Refactors
- remove additional
fetchError
prop from hook return object (d8a3352)
v7.9.0
7.9.0 (2024-09-04)
Features
Description
v7.9.0 merges the functionality of handleServerErrorLog
and handleReturnedServerError
functions into a single optional initialization function called handleServerError
. This change has been made because having two functions for server error handling is unnecessary, you can easily manage both logging and returned error within a single function.
Upgrade guide
Suppose you have this code using next-safe-action < 7.9.0:
import { createSafeActionClient } from "next-safe-action";
const actionClient = createSafeActionClient({
// handles logging
handleServerErrorLog(error) {
console.error("my custom error log:", error.message);
},
// handles returned shape
handleReturnedServerError(error) {
return {
message: error.message,
};
},
});
With next-safe-action >= 7.9.0 it becomes:
import { createSafeActionClient } from "next-safe-action";
const ac = createSafeActionClient({
// handles both logging and returned shape
handleServerError(error) {
console.error("my custom error log:", error.message);
return {
message: error.message,
};
},
});
So, minimal refactoring is required, and the action client creation is cleaner this way.
Note
Even if you want to change just the logging mechanism, you still have to return an error shape from handleServerError
, otherwise the resulting type would be void
.
So, if you want for instance keep the default error message as the returned server error and just update the console logging, you can do it like this:
import { createSafeActionClient, DEFAULT_SERVER_ERROR_MESSAGE } from "next-safe-action";
const ac = createSafeActionClient({
handleServerError(error) {
console.error("my custom error log:", error.message);
return DEFAULT_SERVER_ERROR_MESSAGE;
},
});