Skip to content

Commit

Permalink
Merge pull request #36 from ba-st/moved-http-client-error
Browse files Browse the repository at this point in the history
Moved http client error
  • Loading branch information
fortizpenaloza authored Jun 24, 2019
2 parents 16f1836 + 417d498 commit 5080acd
Show file tree
Hide file tree
Showing 12 changed files with 165 additions and 176 deletions.
2 changes: 1 addition & 1 deletion source/BaselineOfStargate/BaselineOfStargate.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ BaselineOfStargate >> baseline: spec [
spec
group: 'CI' with: 'Tests';
group: 'Examples' with: #('Deployment' 'Stargate-Examples');
group: 'Tools' with: #('Buoy-Tools' 'Teapot-Tools');
group: 'Tools' with: #('Teapot-Tools');
group: 'Development' with: #('Tests' 'Tools')
]
]
Expand Down
4 changes: 2 additions & 2 deletions source/Stargate-Examples/PetsRESTfulController.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ PetsRESTfulController >> defaultPaginationLimit [
{ #category : #API }
PetsRESTfulController >> deletePetBasedOn: anHttpRequest within: aContext [

[ pets remove: (self petIdentifiedUsing: anHttpRequest) ]
[ pets remove: ( self petIdentifiedUsing: anHttpRequest ) ]
on: ObjectNotFound
do: [ :signal | HTTPClientError signalNotFound ].
do: [ :signal | HTTPClientError notFound signal ].

^ ZnResponse noContent
]
Expand Down
104 changes: 104 additions & 0 deletions source/Stargate-MigrationTo2/HTTPClientError.extension.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
Extension { #name : #HTTPClientError }

{ #category : #'*Stargate-MigrationTo2' }
HTTPClientError class >> signalBadRequest: aFailureExplanation [

self
deprecated: 'Use badRequest signal: instead'
on: '2019-06-19'
in: #Stargate2
transformWith: '`@receiver signalBadRequest: `@message' -> '`@receiver badRequest signal: `@message'.

^ self signal: 400 describedBy: aFailureExplanation
]

{ #category : #'*Stargate-MigrationTo2' }
HTTPClientError class >> signalConflict: aFailureExplanation [

self
deprecated: 'Use conflict signal: instead'
on: '2019-06-19'
in: #Stargate2
transformWith: '`@receiver signalConflict: `@message' -> '`@receiver conflict signal: `@message'.

^self signal: 409 describedBy: aFailureExplanation
]

{ #category : #'*Stargate-MigrationTo2' }
HTTPClientError class >> signalNotFound [

self
deprecated: 'Use notFound signal instead'
on: '2019-06-19'
in: #Stargate2
transformWith: '`@receiver signalNotFound' -> '`@receiver notFound signal'.

^ self signal: 404 describedBy: 'Not found'
]

{ #category : #'*Stargate-MigrationTo2' }
HTTPClientError class >> signalNotFound: aFailureExplanation [

self
deprecated: 'Use notFound signal: instead'
on: '2019-06-19'
in: #Stargate2
transformWith: '`@receiver signalNotFound: `@message' -> '`@receiver notFound signal: `@message'.

^ self signal: 404 describedBy: aFailureExplanation
]

{ #category : #'*Stargate-MigrationTo2' }
HTTPClientError class >> signalPreconditionFailed [

self
deprecated: 'Use preconditionFailed signal instead'
on: '2019-06-19'
in: #Stargate2
transformWith: '`@receiver signalPreconditionFailed' -> '`@receiver preconditionFailed signal'.

^ self
signal: 428
describedBy:
'One or more conditions given in the request header fields evaluated to false when tested on the server.'
]

{ #category : #'*Stargate-MigrationTo2' }
HTTPClientError class >> signalPreconditionRequired: aFailureExplanation [

self
deprecated: 'Use preconditionRequired signal: instead'
on: '2019-06-19'
in: #Stargate2
transformWith: '`@receiver signalPreconditionRequired: `@messageText' -> '`@receiver preconditionRequired signal: `@messageText'.

^ self signal: 428 describedBy: aFailureExplanation
]

{ #category : #'*Stargate-MigrationTo2' }
HTTPClientError class >> signalUnprocessableEntity: aFailureExplanation [

self
deprecated: 'Use unprocessableEntity signal: instead'
on: '2019-06-19'
in: #Stargate2
transformWith:
'`@receiver signalUnprocessableEntity: `@message'
-> '`@receiver unprocessableEntity signal: `@message'.

^ self signal: 422 describedBy: aFailureExplanation
]

{ #category : #'*Stargate-MigrationTo2' }
HTTPClientError class >> signalUnsupportedMediaType: aFailureExplanation [

self
deprecated: 'Use unsupportedMediaType signal: instead'
on: '2019-06-19'
in: #Stargate2
transformWith:
'`@receiver signalUnsupportedMediaType: `@message'
-> '`@receiver unsupportedMediaType signal: `@message'.

^ self signal: 415 describedBy: aFailureExplanation
]
1 change: 1 addition & 0 deletions source/Stargate-MigrationTo2/package.st
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Package { #name : #'Stargate-MigrationTo2' }
71 changes: 0 additions & 71 deletions source/Stargate-Model-Tests/HTTPClientErrorTest.class.st

This file was deleted.

16 changes: 16 additions & 0 deletions source/Stargate-Model-Tests/HTTPNotAcceptableTest.extension.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
Extension { #name : #HTTPNotAcceptableTest }

{ #category : #'*Stargate-Model-Tests' }
HTTPNotAcceptableTest >> testNotAcceptableAsJSON [

| error json |

error := HTTPNotAcceptable messageText: 'Ouch!' accepting: {'application/xml' asMediaType}.
json := NeoJSONObject fromString: (NeoJSONWriter toStringPretty: error).

self
assert: json message equals: 'Ouch!';
assert: json code equals: 406;
assert: json allowedMediaTypes size equals: 1;
assert: json allowedMediaTypes first equals: 'application/xml'
]
64 changes: 1 addition & 63 deletions source/Stargate-Model/HTTPClientError.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -7,69 +7,7 @@ Class {
#category : #'Stargate-Model-Controllers'
}

{ #category : #signaling }
HTTPClientError class >> signal: aCode describedBy: aFailureExplanation [

^ self new
tag: aCode;
signal: aFailureExplanation
]

{ #category : #signaling }
HTTPClientError class >> signalBadRequest: aFailureExplanation [

^ self signal: 400 describedBy: aFailureExplanation
]

{ #category : #signaling }
HTTPClientError class >> signalConflict: aFailureExplanation [

^self signal: 409 describedBy: aFailureExplanation
]

{ #category : #signaling }
HTTPClientError class >> signalNotFound [

^self signal: 404 describedBy: 'Not found'
]

{ #category : #signaling }
HTTPClientError class >> signalNotFound: aFailureExplanation [

^self signal: 404 describedBy: aFailureExplanation
]

{ #category : #signaling }
HTTPClientError class >> signalPreconditionFailed [

^ self signal: 412 describedBy: 'One or more conditions given in the request header fields evaluated to false when tested on the server.'
]

{ #category : #signaling }
HTTPClientError class >> signalPreconditionRequired: aMessageText [

^ self signal: 428 describedBy: aMessageText
]

{ #category : #signaling }
HTTPClientError class >> signalUnprocessableEntity: aFailureExplanation [

^ self signal: 422 describedBy: aFailureExplanation
]

{ #category : #signaling }
HTTPClientError class >> signalUnsupportedMediaType: aFailureExplanation [

^ self signal: 415 describedBy: aFailureExplanation
]

{ #category : #accessing }
HTTPClientError >> code [

^self tag
]

{ #category : #converting }
{ #category : #'*Stargate-Model' }
HTTPClientError >> neoJsonOn: neoJSONWriter [

neoJSONWriter
Expand Down
10 changes: 10 additions & 0 deletions source/Stargate-Model/HTTPClientError.extension.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Extension { #name : #HTTPClientError }

{ #category : #'*Stargate-Model' }
HTTPClientError >> neoJsonOn: neoJSONWriter [

neoJSONWriter
writeMap:
{(#code -> self code).
(#message -> self messageText)} asDictionary
]
30 changes: 1 addition & 29 deletions source/Stargate-Model/HTTPNotAcceptable.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -20,35 +20,7 @@ Class {
#category : #'Stargate-Model-Controllers'
}

{ #category : #'instance creation' }
HTTPNotAcceptable class >> messageText: aMessageText accepting: allowedMediaTypes [

^ self new
tag: 406;
messageText: aMessageText;
allowedMediaTypes: allowedMediaTypes asArray;
yourself
]

{ #category : #signalling }
HTTPNotAcceptable class >> signal: aMessageText accepting: allowedMediaTypes [

^ (self messageText: aMessageText accepting: allowedMediaTypes asArray) signal
]

{ #category : #accessing }
HTTPNotAcceptable >> allowedMediaTypes [

^ allowedMediaTypes
]

{ #category : #accessing }
HTTPNotAcceptable >> allowedMediaTypes: anArray [

allowedMediaTypes := anArray
]

{ #category : #converting }
{ #category : #'*Stargate-Model' }
HTTPNotAcceptable >> neoJsonOn: neoJSONWriter [

(neoJSONWriter customMappingFor: ZnMimeType) encoder: [ :mediaType | mediaType asString ].
Expand Down
12 changes: 12 additions & 0 deletions source/Stargate-Model/HTTPNotAcceptable.extension.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
Extension { #name : #HTTPNotAcceptable }

{ #category : #'*Stargate-Model' }
HTTPNotAcceptable >> neoJsonOn: neoJSONWriter [

(neoJSONWriter customMappingFor: ZnMimeType) encoder: [ :mediaType | mediaType asString ].
neoJSONWriter
writeMap:
{(#code -> self code).
(#message -> self messageText).
(#allowedMediaTypes -> self allowedMediaTypes)} asDictionary
]
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ RESTfulControllerPaginateCollectionsPolicy >> evaluateQuery: aQueryEvaluationBlo

pagination := [ self paginationFrom: anHttpRequest ]
on: InstanceCreationFailed
do: [ :error | HTTPClientError signalBadRequest: error messageText ].
do: [ :error | HTTPClientError badRequest signal: error messageText ].
^ resourceController evaluateQuery: [ aQueryEvaluationBlock cull: pagination ]
]

Expand Down
Loading

0 comments on commit 5080acd

Please sign in to comment.