Add try/catch around `fetch()`, style system messages correctly
This commit is contained in:
		
							parent
							
								
									3ff30b4ccb
								
							
						
					
					
						commit
						86bb7f1001
					
				| 
						 | 
				
			
			@ -62,7 +62,9 @@
 | 
			
		|||
    // Show updating bar
 | 
			
		||||
    updating = true;
 | 
			
		||||
 | 
			
		||||
    const response: Response = await (
 | 
			
		||||
    let response: Response;
 | 
			
		||||
    try {
 | 
			
		||||
      response = await (
 | 
			
		||||
        await fetch("https://api.openai.com/v1/chat/completions", {
 | 
			
		||||
          method: "POST",
 | 
			
		||||
          headers: {
 | 
			
		||||
| 
						 | 
				
			
			@ -85,6 +87,9 @@
 | 
			
		|||
          }),
 | 
			
		||||
        })
 | 
			
		||||
      ).json();
 | 
			
		||||
    } catch (e) {
 | 
			
		||||
      response = { error: { message: e.message } };
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // Hide updating bar
 | 
			
		||||
    updating = false;
 | 
			
		||||
| 
						 | 
				
			
			@ -214,6 +219,7 @@
 | 
			
		|||
    </article>
 | 
			
		||||
  {:else if message.role === "system"}
 | 
			
		||||
    <article class="message is-danger">
 | 
			
		||||
      <div class="message-body">
 | 
			
		||||
        <SvelteMarkdown
 | 
			
		||||
          source={message.content}
 | 
			
		||||
          options={markedownOptions}
 | 
			
		||||
| 
						 | 
				
			
			@ -221,6 +227,7 @@
 | 
			
		|||
            /*code: Code*/
 | 
			
		||||
          }}
 | 
			
		||||
        />
 | 
			
		||||
      </div>
 | 
			
		||||
    </article>
 | 
			
		||||
  {:else}
 | 
			
		||||
    <article class="message is-success">
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue