-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for next safe action (#20)
- Loading branch information
1 parent
0985c0d
commit 0e6bc44
Showing
37 changed files
with
830 additions
and
672 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { z } from "zod"; | ||
|
||
export const envUrlSchema = z | ||
.string() | ||
.url() | ||
.endsWith("/graphql/", "Must end with /graphql/"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,8 @@ | ||
import ModernError from "modern-errors"; | ||
import modernErrorsSerialize from "modern-errors-serialize"; | ||
|
||
export const BaseError = ModernError.subclass("BaseError"); | ||
export const BaseError = ModernError.subclass("BaseError", { | ||
plugins: [modernErrorsSerialize], | ||
}); | ||
|
||
export const UnknownError = BaseError.subclass("UnknownError"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { | ||
createSafeActionClient, | ||
DEFAULT_SERVER_ERROR_MESSAGE, | ||
} from "next-safe-action"; | ||
import { z } from "zod"; | ||
|
||
import { BaseError } from "./errors"; | ||
import { createLogger } from "./logger"; | ||
|
||
const logger = createLogger("serverAction"); | ||
|
||
export const actionClient = createSafeActionClient({ | ||
defineMetadataSchema() { | ||
return z.object({ | ||
actionName: z.string(), | ||
}); | ||
}, | ||
handleServerError(error, utils) { | ||
logger.error(`Error during ${utils.metadata.actionName} action handling:`, { | ||
error: error, | ||
actionName: utils.metadata.actionName, | ||
}); | ||
|
||
if (error instanceof BaseError) { | ||
return { | ||
message: error.message, | ||
name: error.name, | ||
}; | ||
} | ||
|
||
return { | ||
message: DEFAULT_SERVER_ERROR_MESSAGE, | ||
name: "Adyen testclient error", | ||
}; | ||
}, | ||
}); |
Oops, something went wrong.