mirror of
				https://gitea.invidious.io/iv-org/shard-kemal.git
				synced 2024-08-15 00:53:36 +00:00 
			
		
		
		
	Added new exception page (#466)
This commit is contained in:
		
							parent
							
								
									d0b4c0d609
								
							
						
					
					
						commit
						a13fe95201
					
				
					 4 changed files with 48 additions and 26 deletions
				
			
		|  | @ -8,6 +8,9 @@ dependencies: | |||
|   kilt: | ||||
|     github: jeromegn/kilt | ||||
|     version: ~> 0.4.0 | ||||
|   exception_page: | ||||
|     github: crystal-loot/exception_page | ||||
|     version: ~> 0.1.1 | ||||
| 
 | ||||
| targets: | ||||
|   kemal: | ||||
|  |  | |||
|  | @ -14,7 +14,7 @@ module Kemal | |||
|       log("Exception: #{ex.inspect_with_backtrace}") | ||||
|       return call_exception_with_status_code(context, ex, 500) if Kemal.config.error_handlers.has_key?(500) | ||||
|       verbosity = Kemal.config.env == "production" ? false : true | ||||
|       return render_500(context, ex.inspect_with_backtrace, verbosity) | ||||
|       return render_500(context, ex, verbosity) | ||||
|     end | ||||
| 
 | ||||
|     private def call_exception_with_status_code(context : HTTP::Server::Context, exception : Exception, status_code : Int32) | ||||
|  |  | |||
							
								
								
									
										38
									
								
								src/kemal/exception_page.cr
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										38
									
								
								src/kemal/exception_page.cr
									
										
									
									
									
										Normal file
									
								
							
										
											
												File diff suppressed because one or more lines are too long
											
										
									
								
							|  | @ -21,32 +21,13 @@ def render_404 | |||
|   HTML | ||||
| end | ||||
| 
 | ||||
| def render_500(context, backtrace, verbosity) | ||||
|   message = if verbosity | ||||
|               "<pre>#{HTML.escape(backtrace)}</pre>" | ||||
| def render_500(context, exception, verbosity) | ||||
|   template = if verbosity | ||||
|                Kemal::ExceptionPage.for_runtime_exception(context, exception).to_s | ||||
|              else | ||||
|               "<p>Something wrong with the server :(</p>" | ||||
|                Kemal::ExceptionPage.for_production_exception | ||||
|              end | ||||
| 
 | ||||
|   template = <<-HTML | ||||
|       <!DOCTYPE html> | ||||
|       <html> | ||||
|       <head> | ||||
|         <style type="text/css"> | ||||
|         body { text-align:center;font-family:helvetica,arial;font-size:22px; | ||||
|           color:#888;margin:20px} | ||||
|         #c {margin:0 auto;width:500px;text-align:left} | ||||
|         pre {text-align:left;font-size:14px;color:#fff;background-color:#222; | ||||
|           font-family:Operator,"Source Code Pro",Menlo,Monaco,Inconsolata,monospace; | ||||
|           line-height:1.5;padding:10px;border-radius:2px;overflow:scroll} | ||||
|         </style> | ||||
|       </head> | ||||
|       <body> | ||||
|         <h2>Kemal has encountered an error. (500)</h2> | ||||
|         #{message} | ||||
|       </body> | ||||
|       </html> | ||||
|   HTML | ||||
|   context.response.status_code = 500 | ||||
|   context.response.print template | ||||
|   context | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue