-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(canary): better error handling (#204)
- Loading branch information
1 parent
c7fe3a7
commit c8b1e83
Showing
3 changed files
with
39 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,12 @@ | ||
import { toast } from 'react-semantic-toasts'; | ||
|
||
export function connectionErrorToast(error) { | ||
toast({ | ||
type: 'error', | ||
icon: 'exclamation circle', | ||
title: 'Error!', | ||
description: 'There was an error communicating with Canary. The error was: "' + error + '"', | ||
time: 5000, | ||
}); | ||
let errMsg = error?.response?.data?.errorDetails ?? error?.response ?? error | ||
toast({ | ||
type: 'error', | ||
icon: 'exclamation circle', | ||
title: 'Error!', | ||
description: 'Error: "' + errMsg + '"', | ||
time: 10000, | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
using Microsoft.AspNetCore.Mvc.Filters; | ||
using Microsoft.AspNetCore.Mvc; | ||
using System; | ||
|
||
namespace canary.Filter | ||
{ | ||
public class ExceptionHandlingFilter : IExceptionFilter | ||
{ | ||
public void OnException(ExceptionContext context) | ||
{ | ||
var exception = context.Exception; | ||
|
||
var errorResponse = new | ||
{ | ||
ErrorDetails = exception.Message | ||
}; | ||
|
||
context.Result = new JsonResult(errorResponse) | ||
{ | ||
StatusCode = 500 | ||
}; | ||
|
||
context.ExceptionHandled = true; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters