1- import { NetworkError , ParseError } from '../../Error/index.js' ;
21import { FetchHelper , Logger , ServiceResolver } from '../../Service/index.js' ;
3- import { Data , UniqueUserIdentifier , Uuid , validateUuidFromString } from '../../Type/Definition/index.js' ;
2+ import { Data , UniqueUserIdentifier , Uuid } from '../../Type/Definition/index.js' ;
43import { ServiceIdentifier } from '../../Type/Enum/index.js' ;
54
65/**
@@ -27,7 +26,7 @@ class PostRegisterEndpoint {
2726 return Promise . resolve ( )
2827 . then ( ( ) => {
2928 const url = this . fetchHelper . buildUrl ( `/register` ) ;
30- this . logger . debug ( `Executing HTTP POST request against url ${ url } . ` ) ;
29+ this . logger . debug ( `Executing HTTP POST request against URL: ${ url } ` ) ;
3130 return fetch (
3231 url ,
3332 this . fetchHelper . getDefaultPostOptions (
@@ -40,31 +39,9 @@ class PostRegisterEndpoint {
4039 ) ,
4140 ) ;
4241 } )
43- . catch ( ( error ) => {
44- throw new NetworkError ( `Experienced generic network error during creating resource.` , error ) ;
45- } )
46- . then ( async ( response : Response ) => {
47- if ( response . ok && response . status === 201 ) {
48- if ( response . headers . has ( 'Location' ) ) {
49- const location = response . headers . get ( 'Location' ) as string ;
50- const rawUuid = location . split ( '/' ) . at ( - 1 ) as string ;
51- return validateUuidFromString ( rawUuid ) ;
52- }
53- }
54- const contentType = response . headers . get ( 'Content-Type' ) ;
55- if ( contentType === null ) {
56- throw new ParseError ( 'Response does not contain content type header.' ) ;
57- }
58- if ( ! contentType . includes ( 'application/problem+json' ) ) {
59- throw new ParseError ( "Unable to parse response as content type is not 'application/problem+json'." ) ;
60- }
61- const data = await response . json ( ) ;
62- throw this . fetchHelper . createResponseErrorFromBadResponse ( response , data ) ;
63- } )
64- . catch ( ( error ) => {
65- this . logger . error ( error . message , error ) ;
66- throw error ;
67- } ) ;
42+ . catch ( ( error ) => this . fetchHelper . rethrowErrorAsNetworkError ( error ) )
43+ . then ( ( response ) => this . fetchHelper . parseLocationResponse ( response ) )
44+ . catch ( ( error ) => this . fetchHelper . logAndThrowError ( error ) ) ;
6845 }
6946}
7047
0 commit comments