Skip to content

Commit

Permalink
add error for cont. token parse error
Browse files Browse the repository at this point in the history
  • Loading branch information
oskogstad committed Jan 14, 2025
1 parent a6518b8 commit 9c7dfd7
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 2 deletions.
4 changes: 4 additions & 0 deletions docs/schema/V1/schema.verified.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,10 @@ type SearchDialog {
seenSinceLastUpdate: [SeenLog!]!
}

type SearchDialogContinuationTokenParsingError implements SearchDialogError {
message: String!
}

type SearchDialogForbidden implements SearchDialogError {
message: String!
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,17 @@ public async Task<SearchDialogsPayload> SearchDialogs(
{
var searchDialogQuery = mapper.Map<SearchDialogQuery>(input);

if (ContinuationTokenSet<SearchDialogQueryOrderDefinition, IntermediateDialogDto>.TryParse(
if (!ContinuationTokenSet<SearchDialogQueryOrderDefinition, IntermediateDialogDto>.TryParse(
input.ContinuationToken, out var continuationTokenSet))
{
searchDialogQuery.ContinuationToken = continuationTokenSet;
return new SearchDialogsPayload
{
Errors = [new SearchDialogContinuationTokenParsingError()]
};
}

searchDialogQuery.ContinuationToken = continuationTokenSet;

OrderSet<SearchDialogQueryOrderDefinition, IntermediateDialogDto>? orderSet = null;
if (input.OrderBy != null && !input.OrderBy.TryToOrderSet(out orderSet))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ public interface ISearchDialogError
public string Message { get; set; }
}

public sealed class SearchDialogContinuationTokenParsingError : ISearchDialogError
{
public string Message { get; set; } = "An error occurred while parsing the ContinuationToken parameter";
}

public sealed class SearchDialogOrderByParsingError : ISearchDialogError
{
public string Message { get; set; } = "An error occurred while parsing the OrderBy parameter";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,16 @@ public class SearchDialogInputValidator : AbstractValidator<SearchDialogInput>
{
public SearchDialogInputValidator()
{
RuleFor(x => x.OrderBy)
.NotNull()
.When(x => x.ContinuationToken != null)
.WithMessage("OrderBy must be set when ContinuationToken is set.");

RuleFor(x => x.ContinuationToken)
.NotNull()
.When(x => x.OrderBy != null)
.WithMessage("ContinuationToken must be set when OrderBy is set.");

RuleFor(x => x.OrderBy)
.NotEmpty()
.When(x => x.OrderBy != null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public static IServiceCollection AddDialogportenGraphQl(this IServiceCollection
.AddType<SearchDialogForbidden>()
.AddType<SetSystemLabelEntityNotFound>()
.AddType<SearchDialogOrderByParsingError>()
.AddType<SearchDialogContinuationTokenParsingError>()
.AddMaxExecutionDepthRule(12)
.AddInstrumentation()
.InitializeOnStartup()
Expand Down

0 comments on commit 9c7dfd7

Please sign in to comment.