File tree Expand file tree Collapse file tree 1 file changed +29
-4
lines changed
components/notion/actions/update-page Expand file tree Collapse file tree 1 file changed +29
-4
lines changed Original file line number Diff line number Diff line change @@ -87,19 +87,44 @@ export default {
8787 properties,
8888 } ;
8989 } ,
90+ parseProperties ( properties ) {
91+ if ( ! properties ) {
92+ return undefined ;
93+ }
94+ if ( typeof properties === "string" ) {
95+ try {
96+ return JSON . parse ( properties ) ;
97+ } catch {
98+ throw new Error ( "Could not parse properties as JSON object" ) ;
99+ }
100+ }
101+ const parsedProperties = { } ;
102+ for ( const [
103+ key ,
104+ value ,
105+ ] of Object . entries ( properties ) ) {
106+ try {
107+ parsedProperties [ key ] = typeof value === "string"
108+ ? JSON . parse ( value )
109+ : value ;
110+ } catch {
111+ parsedProperties [ key ] = value ;
112+ }
113+ }
114+ return parsedProperties ;
115+ } ,
90116 } ,
91117 async run ( { $ } ) {
92118 try {
93- if ( this . properties && typeof this . properties === "string" ) {
94- this . properties = JSON . parse ( this . properties ) ;
95- }
119+ this . properties = this . parseProperties ( this . properties ) ;
120+
96121 const currentPage = await this . notion . retrievePage ( this . pageId ) ;
97122 const page = this . buildPage ( currentPage ) ;
98123 const response = await this . notion . updatePage ( this . pageId , page ) ;
99124 $ . export ( "$summary" , "Updated page successfully" ) ;
100125 return response ;
101126 } catch ( error ) {
102- throw new Error ( error . body ) ;
127+ throw new Error ( error . body || error ) ;
103128 }
104129 } ,
105130} ;
You can’t perform that action at this time.
0 commit comments