File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -4,11 +4,9 @@ const fetchMessages = async () => {
44 try {
55 const response = await fetch ( url ) ;
66 const data = await response . json ( )
7- console . log ( data )
8-
97
108 const messages = document . getElementById ( "messages" )
11- messages . innerHTML = "" ; // avoid duplicatin when u need to call func again
9+ messages . innerHTML = "" ;
1210
1311 if ( data . length === 0 ) {
1412 const noData = document . createElement ( "div" )
@@ -35,8 +33,8 @@ const fetchMessages = async () => {
3533 hour : "2-digit" ,
3634 minute : "2-digit"
3735 } ) ;
38- div . appendChild ( timestamp )
3936
37+ div . appendChild ( timestamp )
4038 messages . appendChild ( div )
4139 }
4240 )
@@ -64,23 +62,24 @@ const sendMessage = async () => {
6462 } )
6563 } )
6664
67- let data ;
68- try {
69- data = await res . json ( ) ;
70- } catch {
71- data = { } ;
72- }
73- if ( ! res . ok ) {
74- showError ( data . error ) ;
75- return ;
76- }
65+ let data ;
66+ try {
67+ data = await res . json ( ) ;
68+ } catch {
69+ data = { } ;
70+ }
71+ if ( ! res . ok ) {
72+ showError ( data . error ) ;
73+ return ;
74+ }
7775
7876 document . getElementById ( "error" ) . textContent = "" ;
7977
8078 // fetchMessages() instead webSocket
8179 document . getElementById ( "user" ) . value = ""
8280 document . getElementById ( "msg" ) . value = ""
8381}
82+
8483const showError = ( msg ) => {
8584 const errorEl = document . getElementById ( "error" ) ;
8685 errorEl . textContent = msg ;
You can’t perform that action at this time.
0 commit comments