-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(update_channel): better errors
using the upstream branch of `ash_graphql` to handle errors in the `update_channel` resource, this commit should be squashed to the previous one when `ash_graphql` releases a new version. Signed-off-by: Luca Zaninotto <[email protected]>
- Loading branch information
Showing
6 changed files
with
91 additions
and
44 deletions.
There are no files selected for viewing
49 changes: 49 additions & 0 deletions
49
backend/lib/edgehog/update_campaigns/update_channel/error_handler.ex
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,49 @@ | ||
# | ||
# This file is part of Edgehog. | ||
# | ||
# Copyright 2025 SECO Mind Srl | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
# | ||
|
||
defmodule Edgehog.UpdateCampaigns.UpdateChannel.ErrorHandler do | ||
@moduledoc false | ||
|
||
def handle_error(error, context) do | ||
%{action: action} = context | ||
|
||
case action do | ||
:create -> target_ids_translation(error) | ||
:update -> target_ids_translation(error) | ||
_ -> error | ||
end | ||
end | ||
|
||
defp target_ids_translation(error) do | ||
if missing_target_ids?(error) do | ||
%{ | ||
error | ||
| fields: [:target_group_ids], | ||
message: "One or more target groups could not be found" | ||
} | ||
else | ||
error | ||
end | ||
end | ||
|
||
defp missing_target_ids?(error) do | ||
error[:code] == "not_found" | ||
end | ||
end |
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
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
Oops, something went wrong.