-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* global error * Apply suggestions from code review Co-authored-by: Nelson Kopliku <nelson.kopliku@suse.com> * format * Return CVEs from `Errata Details` endpoint (#2733) * Return CVEs from `v1/software_updates/errata_details/:advisory_name` * Create CVE factory * global error * Apply suggestions from code review Co-authored-by: Nelson Kopliku <nelson.kopliku@suse.com> * format --------- Co-authored-by: Nelson Kopliku <nelson.kopliku@suse.com> Co-authored-by: Jamie Rodríguez <jamie.rodriguez@suse.com>
- Loading branch information
1 parent
317de10
commit ae5ba8f
Showing
7 changed files
with
133 additions
and
22 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
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
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,20 +1,32 @@ | ||
import { flow, first } from 'lodash'; | ||
import { get, filter } from 'lodash/fp'; | ||
import { get, filter, map } from 'lodash/fp'; | ||
|
||
export const hasError = (keyword, errors) => | ||
errors.some((error) => { | ||
const pointer = get(['source', 'pointer'], error); | ||
const selectField = (keyword) => (error) => { | ||
const pointer = get(['source', 'pointer'], error); | ||
|
||
return pointer === `/${keyword}`; | ||
}); | ||
return pointer === `/${keyword}`; | ||
}; | ||
|
||
export const hasError = (keyword, errors) => errors.some(selectField(keyword)); | ||
|
||
export const getError = (keyword, errors) => | ||
flow([ | ||
filter((error) => { | ||
const pointer = get(['source', 'pointer'], error); | ||
flow([filter(selectField(keyword)), first, get('detail')])(errors); | ||
|
||
return pointer === `/${keyword}`; | ||
}), | ||
export const defaultGlobalError = { | ||
title: 'Unexpected error', | ||
detail: 'Something went wrong.', | ||
}; | ||
|
||
export const getGlobalError = (errors) => | ||
flow([ | ||
filter( | ||
(error) => !(typeof error === 'object' && error && 'source' in error) | ||
), | ||
map((error) => | ||
typeof error === 'object' && error && 'detail' in error | ||
? error | ||
: defaultGlobalError | ||
), | ||
first, | ||
get('detail'), | ||
])(errors); |
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
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