feat: error handling for homepage
This commit is contained in:
parent
2ae093b43d
commit
9071bc23db
8
main.go
8
main.go
@ -36,7 +36,9 @@ func main() {
|
|||||||
body := urlConversionRequest{}
|
body := urlConversionRequest{}
|
||||||
|
|
||||||
if err := c.ShouldBind(&body); err != nil {
|
if err := c.ShouldBind(&body); err != nil {
|
||||||
c.JSON(400, gin.H{"success": false, "message": "Invalid request body"})
|
c.HTML(400, "home.html", gin.H{
|
||||||
|
"errorMessage": "Invalid request body",
|
||||||
|
})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -44,7 +46,9 @@ func main() {
|
|||||||
|
|
||||||
// validate URL
|
// validate URL
|
||||||
if !strings.HasPrefix(soLink, "https://stackoverflow.com/questions/") {
|
if !strings.HasPrefix(soLink, "https://stackoverflow.com/questions/") {
|
||||||
c.JSON(400, gin.H{"success": false, "message": "Invalid URL"})
|
c.HTML(400, "home.html", gin.H{
|
||||||
|
"errorMessage": "Invalid stack overflow URL",
|
||||||
|
})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -66,6 +66,19 @@ body {
|
|||||||
background-color: #3b404b;
|
background-color: #3b404b;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.error {
|
||||||
|
width: 100%;
|
||||||
|
padding: .5rem;
|
||||||
|
background-color: rgb(255, 129, 129);
|
||||||
|
color: black;
|
||||||
|
border-radius: 5px;
|
||||||
|
margin-bottom: 1rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.error p {
|
||||||
|
margin: 0;
|
||||||
|
}
|
||||||
|
|
||||||
@media screen and (max-width: 800px) {
|
@media screen and (max-width: 800px) {
|
||||||
body {
|
body {
|
||||||
padding: 1rem;
|
padding: 1rem;
|
||||||
|
@ -16,9 +16,19 @@
|
|||||||
browsing habits and other browser fingerprint data to
|
browsing habits and other browser fingerprint data to
|
||||||
StackOverflow.
|
StackOverflow.
|
||||||
</p>
|
</p>
|
||||||
|
{{ if .errorMessage }}
|
||||||
|
<div class="error">
|
||||||
|
<p><b>Error</b>: {{ .errorMessage }}</p>
|
||||||
|
</div>
|
||||||
|
{{ end }}
|
||||||
<form method="POST">
|
<form method="POST">
|
||||||
<div class="view-form">
|
<div class="view-form">
|
||||||
<input class="view-input" type="text" name="url" placeholder="https://stackoverflow.com/questions/123456/example-url" />
|
<input
|
||||||
|
class="view-input"
|
||||||
|
type="text"
|
||||||
|
name="url"
|
||||||
|
placeholder="https://stackoverflow.com/questions/123456/example-url"
|
||||||
|
/>
|
||||||
<button class="view-button" type="submit">View</button>
|
<button class="view-button" type="submit">View</button>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user